Created
May 5, 2015 17:05
-
-
Save zstepek/5ac34e29885ded8f0bc4 to your computer and use it in GitHub Desktop.
Change user role after purchase is successful. Need to expand this example to include conditional processing based on products purchased.
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_thankyou', 'mindsize_change_role_on_successful_purchase'); | |
function mindsize_change_role_on_successful_purchase($order_id ) { | |
$order = new WC_Order( $order_id ); | |
$user_id = $order->user_id; | |
$wp_user_object = new WP_User($user_id); | |
if($wp_user_object->roles[0] != "administrator"){ // Do not change admin role | |
wp_update_user( array( 'ID' => $wp_user_object->ID, 'role' => "wholesale" ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment