Add paiment in admin dashboard

Hi i'm trying to create a widget to add a payment option to users that are logged into the wp-admin (dashboard).

I'm using membership 2 pro since it offers possibility to have monthly subscription. Admin create user with role member_basic and they should be able to subscribe and the role will change to member_premium.

I don't know how to do that :slight_frown:

// Create the widget
function paymentDashoboard() {
 // Get current user role
 $user = wp_get_current_user();
 // If user is member_basic
 if ( in_array( 'member_basic', (array) $user->roles ) ) {

    //Here we need to propose to purchase monthly payment

        //If subscribe we just change the user role
        //$user->set_role( 'member_premium' );

 } else if ( in_array( 'member_premium', (array) $user->roles ) ) {

    // Display that he his in member_premium he can cancel when he wants
    // if cancel
    //$user->set_role( 'member_basic' );

 } else {

    // I will list the users for admin but this is fine :)

 }
}
function add_paymentDashboard() {
   wp_add_dashboard_widget( 'paymentDashboard', 'Payment Subscription', 'paymentDashboard' );
}
add_action('wp_dashboard_setup', 'add_paymentDashboard' );

Thanks in advance for your help

  • Bojan Radonic

    Hey Hubert,

    How are you doing today?

    Adding a full payment process from the WP admin is not something that can be done out of a box, it would require a lot of custom coding.

    I've done some testing and what's doable without a lot of customizations is just creating a new widget in dashboard and using [ms-membership-signup] shortcode that will simply display available memberships in the dashboard widget but clicking the link to actually sign up would still be done on the front end.

    If that can work for you, you can check our blog post about creating custom widgets here https://premium.wpmudev.org/blog/adding-custom-widgets-to-the-wordpress-admin-dashboard/, what you want to do is simply execute shortcode instead of having that text that is in the example code in that blog post, this is what you're looking to use:

    echo do_shortcode('[ms-membership-signup]');

    It would look like this:

    With this you should have your memberships displayed in admin but would still have the process on the front end of your site, if you're looking to have the whole process in WP admin this would be out of scope of support that we can provide as it would require a lot of custom coding, if you need to customize this then you can post a job in our job board where you can hire a developer to assist further: https://premium.wpmudev.org/wordpress-development/

    Best regards,
    Bojan