When you apply a coupon code programmatically, for example, you may want to hide the coupon code on the cart and checkout page so that the code stays private and cannot be shared with others.
This solution will basically remove the coupon code (e.g. “VWXYZ”) from the “Coupon: VWXYZ” string that appears in the Cart and Checkout totals. Enjoy!
PHP Snippet: Hide Coupon Code from WooCommerce Cart and Checkout Totals
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: “You Only Need $$$ to Get Free Shipping!” @ 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. Here’s how we show a simple message on the […]
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: Disable Payment Method If Product Category @ Cart Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
WooCommerce: Add Privacy Policy Checkbox @ Checkout Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]
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
Thanks a lot for all these snippets!!!
One question, right now we have the rows as :
– PRODUCT
– SUBTOTAL
– COUPON
Is there a simple trick to get:
– PRODUCT
– COUPON
– SUBTOTAL
Which from my perspective would be much more logical…
Thanks a lot
Hello Manuel, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Thanks for the snippet. I tried it, but it didn’t work. I used the code snippets plugins for it, maybe that is why? Or has Woocommerce changed too mucht by now? Would you test the snippet please?
Thanks, I have learned a lot from your site! Elisabeth
I am doing checkout on the same page as cart and this code did not work for me. I want to know how I can just remove coupon area from the cart area and not from the check out page.
Amir, thanks so much for your comment! 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
Hey Rodolfo, Thank you for all this excellent post about WooCommerceโI use like 20 of your snippets and counting! I have a question related to this post: how can I change the [Remove] text at the end of the line? Maybe with gettext. I searched for an hour now and nobody have written about this on the wide internet.
Hey Peter, thanks so much for your comment! 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
Thanks for your comment Jurasjo, you’re absolutely correct, I just found that out. Hopefully customers are not advanced enough to think if they “Inspect” via Google Chrome they can get the coupon code. Either way, I’m sure there is some additional PHP that can be added to hide the CSS class as well ๐
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!
Thanks a lot for all these snippets!!!
One question, right now we have the rows as :
– PRODUCT
– SUBTOTAL
– COUPON
Is there a simple trick to get:
– PRODUCT
– COUPON
– SUBTOTAL
Which from my perspective would be much more logical…
Thanks a lot
Hello Manuel, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Thanks for the snippet. I tried it, but it didn’t work. I used the code snippets plugins for it, maybe that is why? Or has Woocommerce changed too mucht by now? Would you test the snippet please?
Thanks, I have learned a lot from your site! Elisabeth
Works perfectly, must be something else? Do you have a screenshot for me?
Does not work with a new version of woocommerce, any suggestions?
It works, sorry ๐
Awesome-sauce! Thanks so much, your snippets are so freakin useful! Keep it up Rod
Thanks!
This snippet still works – THANK YOU SO MUCH!!
Awesome!
I am doing checkout on the same page as cart and this code did not work for me. I want to know how I can just remove coupon area from the cart area and not from the check out page.
Amir, thanks so much for your comment! 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
Hey Rodolfo, Thank you for all this excellent post about WooCommerceโI use like 20 of your snippets and counting! I have a question related to this post: how can I change the [Remove] text at the end of the line? Maybe with gettext. I searched for an hour now and nobody have written about this on the wide internet.
Hey Peter, thanks so much for your comment! 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
Still works like a charm.
Excellent, thanks Chris!
There is one catch: woocommerce adds css class like , so coupon code may be revealed !
Thanks for your comment Jurasjo, you’re absolutely correct, I just found that out. Hopefully customers are not advanced enough to think if they “Inspect” via Google Chrome they can get the coupon code. Either way, I’m sure there is some additional PHP that can be added to hide the CSS class as well ๐
Tnx Rodolf, the snippets works.
Awesome ๐