Created
July 25, 2018 12:22
-
-
Save AshishOdich/9d398fea3266f37ba845e98e2d447555 to your computer and use it in GitHub Desktop.
Woo-Commerce(Wordpress) login redirect based on cart
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
function woocommerce_custom_redirects() { | |
// Case1: Non logged user on checkout page (cart empty or not empty) | |
if ( !is_user_logged_in() && is_checkout() ) | |
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); | |
// Case2: Logged user on my account page with something in cart | |
if( is_user_logged_in() && !WC()->cart->is_empty() && is_account_page() ) | |
wp_redirect( get_permalink( get_option('woocommerce_checkout_page_id') ) ); | |
} | |
add_action('template_redirect', 'woocommerce_custom_redirects'); | |
/* You can write this into function.php file of your active theme or child theme or in any plugin file also.*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment