Skip to content

Instantly share code, notes, and snippets.

@max-kk
Last active August 3, 2016 09:11
Show Gist options
  • Save max-kk/9be5c12552e562eac66976172b415748 to your computer and use it in GitHub Desktop.
Save max-kk/9be5c12552e562eac66976172b415748 to your computer and use it in GitHub Desktop.
Redirect Woo cutomsers to profile and Not Woo Customers to Another page
function check_is_customer_or_redirect_contest() {
// Redirect if User does not have permissions
$user = new WP_User( $user_ID );
$is_customer = false;
if ( !empty( $user->roles ) && is_array( $user->roles ) && in_array( 'customer', $user->roles ) ) {
$is_customer = true;
}
if ( $is_customer ) {
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
if ( $myaccount_page_id ) {
$myaccount_page_url = get_permalink( $myaccount_page_id );
}
wp_safe_redirect( $myaccount_page_url );
} else {
wp_safe_redirect( '/contests/' ); // May be need replace URL
}
exit;
}
add_action( 'wp_login', 'check_is_customer_or_redirect_contest');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment