Skip to content

Instantly share code, notes, and snippets.

@zstepek
Created May 5, 2015 17:05
Show Gist options
  • Save zstepek/5ac34e29885ded8f0bc4 to your computer and use it in GitHub Desktop.
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.
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