I want to apply the following 2 cases:
If User not logged in and cart is empty:
then redirect user to login and then my account
If User not logged in and cart has product:
then redirect user to login and after login redirect to checkout
My code is:
function wpse_Nologin_redirect() {
if (
! is_user_logged_in()
&& (is_checkout())
) {
$MyLoginURL = "http://example.in/my-account/";
wp_redirect($MyLoginURL);
exit;
}
}
add_action('template_redirect', 'wpse_Nologin_redirect');
The above code works fine for my first case. But for my second case, when I look through the cart with , my site stops working. if ( sizeof( $woocommerce->cart->cart_contents ) == 0 ) {}
I put this in the functions.php theme.
What am I doing wrong?
thank
source
share