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!).
PHP Snippet: Add Content to the Empty Cart Page – WooCommerce
/**
* @snippet Add Content to Empty Cart Page - WooCommerce
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli, BusinessBloomer.com
* @compatible WooCommerce 4.5
* @community https://businessbloomer.com/club/
*/
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';
}
This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101
Related content
WooCommerce: How to Fix the “Cart is Empty” Issue For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
WooCommerce: Remaining $$$ to Get Free Shipping Notification @ Cart This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. So, here’s how we show a simple message on […]
WooCommerce: Cart and Checkout on the Same Page This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
WooCommerce: Weight-Based Shipping Methods With WooCommerce you get 3 default shipping methods: Flat Rate, Free Shipping, Local Pickup. For each one you can define a cost, however there is no way to set up some “weight” restrictions. So, what if you want to display a rate for orders below 10 kg, and another shipping rate for orders above that […]
WooCommerce: Hide Shipping Method If Shipping Class Is In The Cart Our goal is to check if a Product with a specific Shipping Class is in the Cart, and consequently disabling a shipping rate such as Free Shipping if this is true. This is super useful when there are multiple items in the cart and you don’t want to give free shipping for certain orders for […]
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli
22 thoughts on “WooCommerce: Add Content to Empty Cart Page”
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 ?
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?
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
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' )
}
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!
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.
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.
Questions? Feedback? Customization? Leave your comment now! _____
If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!
hi Rodolfo. working fine.
Nice!
Works great. Thank you sir!
Yay!
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 ?
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?
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.
Thank you Vince! You can also echo a shortcode, such as a WooCommerce “products” shortcode: https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-6
This is just perfect. Combined with some extra div and CSS.
Thank you very much.
Brilliant 🙂
Hello Rodolfo. Working great. Thank you very much. 🙂
If you can help, how can add add the text under shop button?
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
I totally understand 🙂 Thank you
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
instead of the echo function you have used?
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.
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.
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!
Thanks for the quick response,
You’re the best!
🙂
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.
Just to elaborate on Richard’s comment – the ‘Your cart is currently empty’ message can be removed as follows:
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
, 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…
Yep, awesome stuff Sarah 🙂