Created
March 13, 2021 19:04
-
-
Save ppcdias/7b2fa64221943f7eb3b7b68c5e61809d to your computer and use it in GitHub Desktop.
WooCommerce Custom Redirect After Login/Logout/Registration
This file contains hidden or 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 | |
// 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