Created
November 6, 2017 07:58
-
-
Save corsonr/2f21241c0b7efca56b05decef5d5d534 to your computer and use it in GitHub Desktop.
Woo: force user role after order is placed
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
<?php // Do not include this if already open! Code goes in theme functions.php. | |
function woo_force_update_user_role( $order_id ) { | |
$order = new WC_Order( $order_id ); | |
if ( $order->user_id > 0 ) { | |
$user = new WP_User( $order->user_id ); | |
// Remove role | |
$user->remove_role( 'subscriber' ); | |
// Add role | |
$user->add_role( 'customer' ); | |
} | |
} | |
add_action( 'woocommerce_order_status_completed', 'woo_force_update_user_role' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment