• Resolved Roshan Zaid

    (@roshanzaid)


    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="https://abcd.com/wp-content/lo.png"><img class="size-medium wp-image-25512 aligncenter" src="https://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.

    • This topic was modified 4 years, 1 month ago by Roshan Zaid.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @roshanzaid ,

    It looks like the cart empty message requires to have the class cart-empty to show the updated information without reloading the page. I have stripped down your code and here is what works for me –

    remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
    add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );
    
    function custom_empty_cart_message() { ?>
        <div class="col-12 offset-md-1 col-md-10">
        	<div class="cart-empty">
    
        	<a href="https://abcd.com/wp-content/lo.png"><img class="size-medium wp-image-25512 aligncenter" src="https://abcd.com/wp-content/lo.png" alt="" width="300" height="169" /></a>
    
        	<p style="text-align: center; font-weight: bold;">Your Shopping Cart Looks Empty</p>
        	<p style="text-align: center;">Your shopping cart is waiting</br>Give it purpose</p>
        </div>
    </div>
    <?php
    }

    I hope this information helps.

    Thank you ??

    Thread Starter Roshan Zaid

    (@roshanzaid)

    Perfect. Thanks

    • This reply was modified 4 years, 1 month ago by Roshan Zaid.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cart Page is Empty When Item is Removed’ is closed to new replies.