Skip to content

Instantly share code, notes, and snippets.

@corsonr
Created November 6, 2017 07:58
Show Gist options
  • Save corsonr/2f21241c0b7efca56b05decef5d5d534 to your computer and use it in GitHub Desktop.
Save corsonr/2f21241c0b7efca56b05decef5d5d534 to your computer and use it in GitHub Desktop.
Woo: force user role after order is placed
<?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