I wanted to design my own template for Cart Page when the cart is empty. I have added the below snippet to accomplish.
add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
remove_action( 'woocommerce_cart_item_removed', 'action_woocommerce_cart_item_removed', 10);
add_action( 'woocommerce_cart_item_removed', 'custom_empty_cart_message', 10);
function custom_empty_cart_message() {
$html = '<a href="http://abcd.com/wp-content/lo.png"><img class="size-medium wp-image-25512 aligncenter" src="http://abcd.com/wp-content/lo.png" alt="" width="300" height="169" /></a>';
$html .= wp_kses_post( apply_filters( 'wc_empty_cart_message', __( '<p style="text-align: center;"><B>Your Shopping Cart Looks Empty</B></p><p style="text-align: center;">Your shopping cart is waiting</br>Give it purpose</p>', 'woocommerce' ) ) );
echo $html . '</p></div>';
}
What happens now is, It works fine when you directly visit the cart page. except when an item is added to the cart -> visiting cart page -> removing the item that has been added shows a blank page instead of the custom method I have created. then if the page is refreshed, it works fine custom method is loads perfect. Why this happens? Why am I seeing a blank page once an item is removed?
Cheers in Advance.
2
Answers
Found out.
The solution is you have to use cart-empty class along with your method as below.
Happy Customizing.
There is this file in WooCommerce
wp-content/plugins/woocommerce/templates/cart/cart-empty.php
You can duplicate this page (with the folder structure) in your theme, and you should be able to customise it !
Have a look at https://docs.woocommerce.com/document/template-structure/