There are many plugins that allow you to setup special accounts for your wholesalers for example. Often times the user role feature of WordPress is used to identify users within a specific group. In this post I’ll show some examples of how you can display/hide prices for specific user groups, including only for specific products / categories.
The snippets in this post will only be for hiding prices, it will still continue users to add products to the cart.
Hiding all the prices
Lets start with a simple script first. This is a example of how you can hide all the prices no matter who is viewing.
I’ve made it so that it does still show prices on the admin, but you can easily comment that line out if you also want to hide prices there.
This code snippet hides all the prices on the product / archive pages, but not on the cart/checkout pages (or the cart widget). The following code also removes the cart item price / subtotal and the same for the checkout.
After using this code snippet it will leave the headings in the table. Unfortunately these cannot be removed with a code snippet, but there are two alternatives.
- By modifying the WooCommerce template files you can remove the columns from the totals table. The totals table is located in the
cart/cart.php
template file. - You can hide them with CSS. A technical user could still uncover the product prices through, so depending on how important it is, this may or may not fit your requirements.
Here’s a CSS snippet that hides the prices on the items on the cart/checkout table and the cart widget:
/* Cart widget */ .woocommerce-mini-cart__total { display: none; } /* Cart */ .product-price, .product-subtotal { display: none !important; } /* Checkout */ .product-total *, th.product-total { display: none; }
Again, this is not a foolproof solution.
Hiding prices for specific user roles
In the below code snippet it will hide the prices for all users with the ‘wholesale’ user role. In the sample code I’ve added multiple rows to show how you can can hide prices for different user roles. Adding more options to it is possible by following the shown format.
Hiding prices for guest users
To only hide it for guest users you can use the following simplified version;
Hiding prices in specific categories
With this version of the code snippet you can target specific categories to hide the prices for.
You can either modify the set categories to the slug of ID of the category.
If wanted you can also combine the snippets to only hide the prices in specific categories for a guest user;
Hiding prices for specific products
Here’s one last version where it only hides the prices for specific products based on the product ID.
Hope you’ve found this post helpful!
103 thoughts on “Hiding product prices in WooCommerce”
Hey Jeroen,
Thanks for the post! This helped me out a lot getting started customising a site to selectively hide prices based on “Woocommerce Memberships” and “Categories”.
Cheers
Roger
Hi Jeroen,
Thank you. it really helped! Is it possible to hide prices for specific products on shop and single product page but display on cart, cart total and checkout?
Hi Wayne,
You can use these code snippets as a basis, and add some additional code to do allow them to show on the cart/checkout pages accordingly.
I don’t have something ready to go for that though.
Cheers,
Jeroen
Hi Wayne,
Did you sort this out? I am trying to do the same thing, but haven’t yet figured it out. I see the price in the subtotal, but the price is showing as 1 rather than the actual price in the cart.
Thanks in advance for the help.
Jeroen Hello,
First of all thank you for sharing code. I want to hide the prices of all the products on my website but I do not know where to add the codes you give. Could you please give me information? Where do I add the codes?
I’ve written a blog post about how you can add a code snippet to your site. You can find it here:
https://aceplugins.com/how-to-add-a-code-snippet/
Hi Jeroen,
I tried the ‘hiding prices in specific categories’ but it also hides the prices in the cart page for all products added to cart, not just those in the category. Any chance you can update this?
Hey amazing article!! thank you! helped me a long way. Was wondering if you can help compare the title of the product. i want to hide prices for products that have “trade” in the product title. Also have an attribute trade=yes which I can use aswellbut i dont know how to. Tried the following but it didnt work;
$page_title =get_the_title();
if (strpos($page_title, ‘Trade) !== false) {
What does the ‘ }, 10, 2 ); ‘ do in the last line of the code to hide categories?
I’m trying to: HIDE prices UNLESS the user is logged in AND/OR the product has a TAG of ‘highlight’. I’m stumped!
Never mind! I’ve figured it out! Thank you for an excellent resource. I wouldn’t have been able to meet my client’s request if it weren’t for this page!! Thank you!!
Good Article.
But you DIDN’T mention the exact file name / directory where you will do all these changes.
Please guide with the file names and path. so it will be very easy for beginners to hide the prices.
Thank You
I’ve written a blog post about how you can add a code snippet to your site. You can find it here:
https://aceplugins.com/how-to-add-a-code-snippet/
Including all that information in each separate post I write with code snippets would be too much 😉
Hi Jeroen,
I tried the ‘hiding prices in specific categories’ but it also hides the prices in the cart page for all products added to cart, not just those in the category. Any chance you can update this?
Hi Azeem,
The content posted about hiding prices in the cart indeed only applied to all prices. The other code snippet about the categories is separated from that and shouldn’t hide any other prices. If you look at the code you’ll see it will only apply to the given product.
Maybe you also have the code that hides the prices in the cart applied before?
Cheers,
Jeroen
I can confirm that this code DOES hide line item prices in the cart and checkout pages for ALL products, not just those in the targeted category. And in the Woo Storefront theme the prices disappear in the header cart too.
Removing the code and the prices re-appear. Putting the code back in and the prices disappear.
Hello, I want replace product price with a text “Register to see price” . This only for guest. Can u help me?
Hello,
is it possible to hide only the prices in one language when using WPML? I have a client that sells products only within Germany but still has his onlineshop in 2 languages (german/english). So he wants to show the prices in the german translation but not in the english one.
Thanks!
Hi Elle,
It is possible to create a conditional check for the language in WPML, but I don’t have that code at hand..
Hi Jeroen, thanks for the solution. I applied the code “Hiding prices for specific user roles”. At 1st it works well to hide the price for “Contributor”. I changed the function to hide the selling price to “Subscriber” instead, then the snippet seems stops functioning. Now the prices are not hidden to the “Subscriber”. Any idea what happened?
Are you sure you’re viewing the site as a subscriber role?
Hi och thanks a lot for this! 🙂
Just one problem left, in the cart and kassa stil show the “subtotal”, can you help me hide this part as well? 🙂
Hi Emma,
Those can be hidden with the CSS that is in the post above.
Hi Jeroen, thank you very much, you give me the right code and solved my problem!
Is it possible to remove the pricing from the Woocommerce customer emails?
Is it possible to change the price for soldout?
Hi,
I need to remove prices from the product listings ‘shop’ page. Once the visitor gets to the product specific page it is fine.
Any advice greatly appreciated.
Hi JonP,
I just published a blog post on my other site that shows how you can do that!
https://aceplugins.com/hide-prices-on-the-category-pages/
Cheers,
Jeroen
Hi Jeroen,
First of all thank you so much for this accurate guideline.
Unfortunately, I am struggling to get it right.
I am trying to add the custom CSS for my themify theme to not show prices for the categories –> canvas, spraypaint on canvas using the the code as below:
add_filter( ‘woocommerce_get_price_html’, function( $price, $product ) {
if ( is_admin() ) return $price;
// Hide for these category slugs / IDs
$hide_for_categories = array( ‘canvas’, ‘spraypaint on canvas’ );
// Don’t show price when its in one of the categories
if ( has_term( $hide_for_categories, ‘product_cat’, $product->get_id() ) ) {
return ”;
}
return $price; // Return original price
}, 10, 2 );
add_filter( ‘woocommerce_cart_item_price’, ‘__return_false’ );
add_filter( ‘woocommerce_cart_item_subtotal’, ‘__return_false’ );
view raw
What am I doing wrong?
Hi Rahmi,
Your slug for the spraypaint category is definitely incorrect, it cannot contain spaces.
Other then that I can’t really see anything wrong with the code.
Cheers,
Jeroen
Thank you so much, Jeroen!
Everything works like a charm now.
All the best,
Rahmi
Hi Jeroen,
I tried your code snippet to hide prices for a specific categories, but it hides prices in the cart and checkout page for all products, not just for the categories that I need (“medici” and “dentisti”).
Could you please help me?
Thanks in advance.
Kind Regards,
Luca
PS: Here below you can find the code snippet that I have added on my function.php:
add_filter( ‘woocommerce_get_price_html’, function( $price, $product ) {
if ( is_admin() ) return $price;
// Hide for these category slugs / IDs
$hide_for_categories = array( ‘medici’ , ‘dentisti’ );
// Don’t show price when its in one of the categories
if ( has_term( $hide_for_categories, ‘product_cat’, $product->get_id() ) ) {
return ”;
}
return $price; // Return original price
}, 10, 2 );
add_filter( ‘woocommerce_cart_item_price’, ‘__return_false’ );
add_filter( ‘woocommerce_cart_item_subtotal’, ‘__return_false’ );
Hi Luca,
The last two lines are what is hiding the prices on the cart/checkout. Remove those 2 and it should re-appear.
Cheers,
Jeroen
Hi Jeroen,
thanks for your reply.
I know that the last two lines hiding all prices on the cart/checkout, but I should still hide only the prices of the specifics category (“medici” and “dentisti”) in the cart/checkout.
Is there a solution for this?
Otherwise I would need a snippet code to hide priceson the cart/checkout page when that are 0.
Thanks in advance.
Cheers,
Luca