Replies: 0
Hi there!
I’m trying to add a conditional redirection to the cart page when a customer get logged and there is something in the cart.
I’m currently using this code :
/* Redirect to cart after logged in when something in cart */
function wc_custom_redirect_cart() {
if( is_account_page() && is_user_logged_in() && !WC()->cart->is_empty() )
wp_redirect( get_permalink( get_option('woocommerce_cart_page_id') ) );
}
add_action( 'template_redirect' , 'wc_custom_redirect_cart' );
It works very fine. However, I’m also getting redirected to the cart page when I’m trying to get logged out.
The issue get fixed when I add a function wp_logout redirection. But It override the function I’m using for custom redirection after registration…
Here is the code :
/* Redirect after registration */
function wc_registration_redirect( $redirect_to ) {
wp_logout();
wp_redirect( pll__('/en/successful-registration/') );
exit;
}
add_filter('woocommerce_registration_redirect', 'wc_registration_redirect');
I was played around this code for days but cannot figure out of it. If you guys have any idea to help it would be great 🙂
Cheers!