Created
March 7, 2017 06:22
-
-
Save hiendnguyen/c35d0f7145d6e735001fe17fccb7ae9f to your computer and use it in GitHub Desktop.
WooCommerce Registration Custom Fields Utilities
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 | |
/*** Change default login url to WooCommerce My Account ***/ | |
function my_login_page( $login_url, $redirect ) { | |
$myaccount_url = get_permalink(wc_get_page_id('myaccount')); | |
return $redirect == '' ? $myaccount_url : $myaccount_url . '?redirect_to=' . $redirect; | |
} | |
add_filter( 'login_url', 'my_login_page', 10, 2 ); | |
/*** We don't want "account page" displays after login by default. We want to display homepage instead ***/ | |
function wooc_user_redirect( $redirect, $user ) { | |
if(isset($_GET['redirect_to'])){ | |
$redirect = $_GET['redirect_to']; | |
} else { | |
$redirect = home_url(); | |
} | |
return $redirect; | |
} | |
add_filter( 'woocommerce_login_redirect', 'wooc_user_redirect', 10, 2 ); | |
/** Prevent automatic login by logoff and show tooltip reminding user to check their mailbox for login credentials. */ | |
function wooc_registration_redirect( $redirect_to ) { | |
$current_user = wp_get_current_user(); | |
wp_logout(); | |
wp_redirect( $myaccount_url = get_permalink(wc_get_page_id('myaccount')) . '?context=RegistrationSucceeded&email=' . $current_user->user_email); | |
exit; | |
} | |
add_filter('woocommerce_registration_redirect', 'wooc_registration_redirect'); | |
function wooc_init(){ | |
if(isset($_GET['context']) && $_GET['context'] == 'RegistrationSucceeded'){ | |
if(isset($_GET['email'])){ | |
wc_add_notice( __( 'We’ve sent a message to ' . $_GET['email'] . '. Open it up for Login Credentials. We’ll take it from there.', 'inkfool' ) ); | |
} | |
else{ | |
wc_add_notice( __( 'We’ve sent a message to you. Open it up for Login Credentials. We’ll take it from there.', 'inkfool' ) ); | |
} | |
} | |
} | |
add_action( 'init', 'wooc_init' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment