add_action( 'woocommerce_order_status_completed', 'vap_change_role_on_purchase_gold' ); function vap_change_role_on_purchase_gold( $order_id ) { // get order object and items $order = new WC_Order( $order_id ); $items = $order->get_items(); $product_id = 2355; // that's a specific product ID foreach ( $items as $item ) { if( $product_id == $item['product_id'] && $order->user_id ) { $user = new WP_User( $order->user_id ); // Remove old role $user->remove_role( 'customer' ); // Add new role $user->add_role( 'pmpro_role_3' ); } } }