Code to force assignment of user group.
-
I am currently using a snippet of PHP code to change a user’s site role after a woocommerce order is completed. ‘Customer’ to ‘Customer Paid’.
Using UAM, I want to then assign access privileges only for ‘Customer Paid’ user roles. However, UAM is not completing the user group assignment after the site role has been changed (even with role affiliation active). So, I am wondering if there is any PHP code I can add to the following that will force UAM to assign the required user group.
//* Change User Role to Customer Paid on Payment Only add_action( 'woocommerce_order_status_completed', 'envy_paid_customer' ); function envy_paid_customer( $order_id ) { $order = new WC_Order( $order_id ); if ( $order->user_id > 0 ) { update_user_meta( $order->user_id, 'paying_customer', 1 ); $user = new WP_User( $order->user_id ); // Remove role $user->remove_role( 'customer' ); // Add role $user->add_role( 'custmr_paid' ); } }
Many thanks in advance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Code to force assignment of user group.’ is closed to new replies.