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.

  1. 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.
  2. 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!

Jeroen Sormani

I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

Interested in talking about a WordPress project? Get in touch!

Follow me on Twitter

103 thoughts on “Hiding product prices in WooCommerce

Roger Woodroofe December 6, 2017 at 5:16 am

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

Wayne December 29, 2017 at 6:12 pm

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?

Jeroen December 30, 2017 at 2:39 pm

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

Carrie May 2, 2018 at 7:19 pm

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.

Hasan January 29, 2018 at 3:53 pm

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?

Jeroen January 29, 2018 at 6:05 pm

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/

Brett January 31, 2018 at 6:42 am

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?

Wazo February 5, 2018 at 1:51 am

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) {

Jarrod February 5, 2018 at 7:31 am

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!

Jarrod February 5, 2018 at 10:56 am

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!!

Rafi Ullah March 18, 2018 at 7:53 am

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

Jeroen Sormani March 18, 2018 at 6:14 pm

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 😉

Azeem March 28, 2018 at 12:29 am

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?

Jeroen Sormani March 28, 2018 at 1:44 pm

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

seoidau May 30, 2018 at 4:11 am

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.

Michele April 5, 2018 at 1:07 pm

Hello, I want replace product price with a text “Register to see price” . This only for guest. Can u help me?

Elle June 11, 2018 at 10:36 am

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!

Jeroen Sormani June 12, 2018 at 10:16 am

Hi Elle,

It is possible to create a conditional check for the language in WPML, but I don’t have that code at hand..

Tan June 12, 2018 at 5:24 pm

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?

Jeroen Sormani June 13, 2018 at 8:40 am

Are you sure you’re viewing the site as a subscriber role?

Emma Olofsson June 18, 2018 at 10:50 am

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? 🙂

Jeroen Sormani June 19, 2018 at 9:35 am

Hi Emma,

Those can be hidden with the CSS that is in the post above.

Stena July 12, 2018 at 12:30 am

Hi Jeroen, thank you very much, you give me the right code and solved my problem!

Ash July 25, 2018 at 2:58 pm

Is it possible to remove the pricing from the Woocommerce customer emails?

gabriel bau July 26, 2018 at 9:58 pm

Is it possible to change the price for soldout?

JonP August 1, 2018 at 10:19 pm

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.

Jeroen Sormani August 15, 2018 at 9:22 am

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

rahmi August 11, 2018 at 12:03 pm

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?

Jeroen Sormani August 15, 2018 at 9:26 am

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

Rahmi August 19, 2018 at 11:32 pm

Thank you so much, Jeroen!

Everything works like a charm now.

All the best,
Rahmi

Luca August 21, 2018 at 7:17 pm

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’ );

Jeroen Sormani August 22, 2018 at 9:17 am

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

Luca August 22, 2018 at 12:35 pm

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

Leave a Reply