• 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.

    https://www.ads-software.com/plugins/user-access-manager/

Viewing 1 replies (of 1 total)
  • I don’t know if this is any help… but I just found this comment about a problem with how UAM stores the role… https://kuchenundkakao.wordpress.com/

    I was hoping to use UAM, but it appears that it is no longer being supported… the link to GM-ALEX site where he says to post bugs gave a 404 error.

Viewing 1 replies (of 1 total)
  • The topic ‘Code to force assignment of user group.’ is closed to new replies.