Created
February 11, 2019 05:24
-
-
Save mrgarry043/ad89891d8090956592a70aafd23200c4 to your computer and use it in GitHub Desktop.
user role
This file contains 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', 'wpglorify_change_role_on_purchase' ); | |
function wpglorify_change_role_on_purchase( $order_id ) { | |
// get order object and items | |
$order = new WC_Order( $order_id ); | |
$items = $order->get_items(); | |
$product_id = 56; // 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 role | |
$user->remove_role( 'subscriber' ); | |
// Add role | |
$user->add_role( 'editor' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment