Help to connect woocommerce_payment_complete with Membership2

Hello we wanted to make an inquiry since we are developing a plugin that interconnects 2 of our plugin woocomerce and membership2 with the objective of creating the memberships automatically once the users make the payment in a satisfactory way (more specifically when ‘woocommerce_payment_complete’ ). Any tip that you can offer us is grateful in advance.

  • Rupok
    • Support Ninja

    Hi Cultiva Tus Ideas,

    Thanks for asking. I’m afraid, there is no direct integration with WooCommerce payment with Membership assigning but you can take idea from the following code snippet:

    add_action( 'user_register', 'assign_membership_on_register', 10, 1 );
    function assign_membership_on_register( $user_id ) {

    $membership = array(
    // 'role' => 'membership ID'
    'abc' => 123,
    'xyz' => 456

    $user_meta = get_userdata( $user_id );
    $user_roles = $user_meta->roles;

    $member = MS_Factory::load( 'MS_Model_Member', $user_id );
    $subscription = $member->add_membership( $membership[ $user_roles[0] ] );

    if ( $member->has_membership() ) {
    $member->is_member = true;
    } else {
    $member->is_member = false;

    This code assigns a membership when user role is changed. You can modify this to match your target payment in WooCommerce.

    I believe, this will help. Please let us know if you have any confusion or any further query. We will be glad to help.

    Have a nice day. Cheers!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.