Created
March 7, 2016 11:46
-
-
Save SirDarcanos/27f64a83a2576a966a50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_order_status_completed', 'change_role_on_purchase' ); | |
function change_role_on_purchase( $order_id ) { | |
$order = wc_get_order( $order_id ); | |
$items = $order->get_items(); | |
$products_to_check = array( '1', '2', '3' ); | |
foreach ( $items as $item ) { | |
if ( $order->user_id > 0 && in_array( $item['product_id'], $products_to_check ) ) { | |
$user = new WP_User( $order->user_id ); | |
// Change role | |
$user->remove_role( 'customer' ); | |
$user->add_role( 'new-role' ); | |
// Exit the loop | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment