• I am trying to sync UM roles to WC memberships which are given to users upon purchase of selected items. So if someone buys a Silver package, they get the Silver WC membership and it should result in a Silver UM role as well. Here’s what I have so far:

    function sync_um_role_to_wc($order_id) {
    $order = new WC_Order( $order_id );
    $user_id = $order->user_id;
    global $ultimatemember;
    um_fetch_user( $user_id );

    if (wc_memberships_is_user_active_member($user_id, 724))
    $ultimatemember->user->set_role( ‘Gold’ );
    else if (wc_memberships_is_user_active_member($user_id, 718))
    $ultimatemember->user->set_role( ‘Silver’);
    else if (wc_memberships_is_user_active_member($user_id, 725))
    $ultimatemember->user->set_role( ‘Diamond’ );
    }

    add_action( ‘wc_memberships_grant_membership_access_from_purchase’, ‘sync_um_role_to_wc’, 10, 2 );

    It seems that I am referencing the wrong user ID, but I’m not too sure. I have tried hooking to other functions but they all don’t seem to work. Any suggestions?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WC membership + UM sync’ is closed to new replies.