Skip to content

Instantly share code, notes, and snippets.

@hiendnguyen
Created March 7, 2017 06:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiendnguyen/c35d0f7145d6e735001fe17fccb7ae9f to your computer and use it in GitHub Desktop.
Save hiendnguyen/c35d0f7145d6e735001fe17fccb7ae9f to your computer and use it in GitHub Desktop.
WooCommerce Registration Custom Fields Utilities
<?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