Posted on

WooCommerce: Add Content to Empty Cart Page

A Business Bloomer fan asked me a great question: “I’m using your visual hook guide to add content above the cart, however I notice that it doesn’t work if the cart is empty. Are there hooks specifically for empty carts?“.

Well, let’s take a look if we have anything available… (hint: of course we do!).

WooCommerce: add content to the empty cart page

PHP Snippet: Add Content to the Empty Cart Page – WooCommerce


/**
 * @snippet       Add Content to Empty Cart Page - WooCommerce
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=21585
 * @author        Rodolfo Melogli
 * @compatible    WC 2.6.14, WP 4.7.2, PHP 5.5.9
 */

add_action( 'woocommerce_cart_is_empty', 'bbloomer_add_content_empty_cart' );

function bbloomer_add_content_empty_cart() {
echo 'This will show on the empty cart page';
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

18 thoughts on “WooCommerce: Add Content to Empty Cart Page

  1. Couple of things

    1) Thanks for add content snippet – working just fine

    2) I’m having a heck of a problem CSS targeting the return to shop button so just want to remove it but it’s a filter rather than an action I think (woocommerce_return_to_shop_redirect). What is best way to remove it ?

    1. Hey Richard, thanks for your comment! Unfortunately you can’t remove the button without overriding the cart-empty.php template files. Why not changing the call to action and redirect URL instead?

  2. Hi,

    It has been a year since this post but is it possible to list products instead of just writing a text?

    Great blog and video series by the way.

    Thanks a lot.

    1. Thank you Vince! You can also echo a shortcode, such as a WooCommerce “products” shortcode: https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-6

    2. This is just perfect. Combined with some extra div and CSS.

      Thank you very much.

  3. Hello Rodolfo. Working great. Thank you very much. 🙂

    If you can help, how can add add the text under shop button?

    1. Excellent, thanks Jerina! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. I totally understand 🙂 Thank you

  4. Hi Rodolfo,

    Enjoying your blog – a lot of great tips on Woocommerce for a first-time WC developer like me.

    I had a question.. in your example above, you use the echo function to output the text. But throughout the WC code, I’ve noticed they use __() or _e() function to output text. Would it be better to use the following

    function bbloomer_add_content_empty_cart() {
      _e( 'Your cart is currently empty.', 'woocommerce' )
    }

    instead of the echo function you have used?

    1. Hey Maclein, thanks for your comment! Yes, of course, that is a way to make the string translatable – a much better way to echo strings.

  5. Hi Rodolfo,

    I need to add content (Text and image) about the “your cart is currently empty” text.

    Your amazing snippet adds text below the “your cart is currently empty” text.

    Please advise.

    Looking forward to hearing from you.

    1. Hello Kelly, thanks for your comment! Unfortunately you can’t, as the “woocommerce_cart_is_empty” hook gets called after the ‘Your cart is currently empty.’ string, so there is no way to do so without overriding the template. FYI, I asked WooCommerce to enhance this: https://github.com/woocommerce/woocommerce/issues/14519 – hope this helps!

    2. Thanks for the quick response,
      You’re the best!

    3. Just a thought (for anyone reading this now, a year later). Remove the your cart is empty action (wc_empty_cart_message) and then add whatever text and image you want below it.

    4. Just to elaborate on Richard’s comment – the ‘Your cart is currently empty’ message can be removed as follows:

      remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );

      A similar approach can be used across any WC template. The way to work it out is to take a look at the e.g. cart-empty.php template – before the call to

      do_action( 'woocommerce_cart_is_empty' );

      , there’s a comment
      /* * @hooked wc_empty_cart_message – 10 */ – that tells you which action to remove, and the associated priority number.

      Hope that helps someone reading this post…

    5. Yep, awesome stuff Sarah 🙂

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.