Skip to content

Instantly share code, notes, and snippets.

@ppcdias
Created March 13, 2021 19:04
Show Gist options
  • Save ppcdias/7b2fa64221943f7eb3b7b68c5e61809d to your computer and use it in GitHub Desktop.
Save ppcdias/7b2fa64221943f7eb3b7b68c5e61809d to your computer and use it in GitHub Desktop.
WooCommerce Custom Redirect After Login/Logout/Registration
<?php
// Add the following code to the functions.php file of your child theme
/**
* WooCommerce Custom Redirect After Login
*/
add_action('woocommerce_login_redirect', 'custom_redirect_after_login');
function custom_redirect_after_login() {
$redirect = get_permalink(wc_get_page_id('myaccount'));
//$redirect = get_home_url(); // home page
//$redirect = admin_url(); // admin dashboard
return $redirect;
}
/**
* WooCommerce Custom Redirect After Logout
*/
add_action('wp_logout', 'custom_redirect_after_logout');
function custom_redirect_after_logout() {
wp_redirect(get_permalink(wc_get_page_id('myaccount')));
exit();
}
/**
* WooCommerce Custom Redirect After Registration
*/
add_filter('woocommerce_registration_redirect', 'custom_redirect_after_registration');
function custom_redirect_after_registration() {
$redirect = get_permalink(wc_get_page_id('myaccount'));
//$redirect = get_home_url(); // home page
//$redirect = get_permalink(wc_get_page_id('shop')); // shop page
//$redirect = wc_get_cart_url(); // cart page
//$redirect = wc_get_checkout_url(); // checkout page
return $redirect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment