Skip to content

Instantly share code, notes, and snippets.

@mikeyarce
Created November 30, 2023 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeyarce/33029c1825554d999805c04b01d3c609 to your computer and use it in GitHub Desktop.
Save mikeyarce/33029c1825554d999805c04b01d3c609 to your computer and use it in GitHub Desktop.
Set role after checkout for WooCommerce
<?php
/**
* Set the default role to employer after checkout.
*
* @param int $order_id
* @return void
*/
function marce_set_employer_role_after_checkout( $order_id ) {
$order = new WC_Order( $order_id );
$user = $order->get_user();
if( false !== $user && ! user_can( $user, 'administrator' ) ){
$role = 'employer';
$user->set_role( $role );
}
}
add_action( 'woocommerce_thankyou', 'marce_set_employer_role_after_checkout', 100, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment