Skip to content

Instantly share code, notes, and snippets.

View AshishOdich's full-sized avatar

Ashish Odich AshishOdich

View GitHub Profile
@AshishOdich
AshishOdich / function.php
Created July 25, 2018 12:22
Woo-Commerce(Wordpress) login redirect based on cart
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') ) );
}