In WooCommerce, if your cart is empty, then the checkout page redirects you to the cart. It is a by-default or original WooCommerce setting. However, you do not want to activate this function every time and skip checkout redirects. So, in this article, you will learn how to show checkout even if cart is empty.
WooCommerce facilitates two great filters which you can use to deactivate such default functions. So, it is easy to enable this functionality.
Read the guide further to get a complete know-how.
PHP Snippet: WooCommerce Show Checkout Even If Cart is Empty or Avoid Redirect when cart is empty
add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' ); add_filter( 'woocommerce_checkout_update_order_review_expired', '__return_false' );
Where do you add this snippet?
So, this is how you show checkout even if cart is empty in WooCommerce. Doing so, the checkout redirects will stop and your website visitor will stay at the checkout. Also, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. Make sure that you are editing these files in a right manner for best results.
Is this snippet still valid?
So, this way, you show checkout even if cart is empty in WooCommerce. Doing so, you can alter by-default function to redirect to cart page when cart is vacant at checkout page. I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected when you code. Share it further if you find this snippet useful for you and it had saved your time.
Important links: WooCommerce – https://woocommerce.com/