I'm developing my own theme Woocommerce , and now I need to do a redirect after logging in a particular page where I am using Woocommerce login form. To this I added the following function in functions.php
if (!is_account_page()) {
add_filter('woocommerce_login_redirect', 'redirect_after_login_cart');
function redirect_after_login_cart(){
wp_redirect( get_permalink( get_page_by_path(‘checkout’) ) );
exit;
}
}
I want only the login-cart page, do the redirect after login to the checkout page. The form of the my-account is still redirecting to the my-account page. The way it is , all my Woocommerce login forms are redirecting to the checkout page. The conditional is not being respected.
Before going to the checkout page, I check if you are logged in or not. If you are logged in, redirect to checkout, but redirects to a page created with the login form. When logging on that page, instead of going to my account page, redirects to the checkout.
The default Woocommerce is every time you log in, go to my account, and I'm changing this form only if you are on page I created login-cart
add_action('template_redirect','check_if_logged_in');
function check_if_logged_in(){
if(!is_user_logged_in() && is_checkout()){
wp_redirect( get_permalink( get_page_by_path('login-cart') ) );
exit;
}
}
If anyone can help me , I will be very grateful .
add_filter()
call - otherwise you risk calling a function that doesn't exist. – Tim Malone