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

98 thoughts on “Hiding product prices in WooCommerce

Jeroen Sormani August 23, 2018 at 11:07 am

I don’t have a ready to go code snippet that will hide those prices only for those categories. You’d have to further customize these snippets to fit your exact requirements.

John August 30, 2018 at 2:46 pm

I have an amazon affiliate store using the theme storefront by WooCommerce. My products were direct imported via Wzone. Apparently the product prices and availability being displayed on my site place in non-compliance with Amazon’s affiliate policies. I have several product categories that all show pricing and availability. This would not be an issue if these things were synced using Amazon’s PA API however they won’t allow access until you are fully accepted. What would be the best method to remove pricing/availability being displayed?

George September 6, 2018 at 4:30 am

How about removing the price from related products?

Jeroen Sormani September 6, 2018 at 10:09 am

If you use the first code snippet it should remove the prices from related products too – any product price really..

John September 6, 2018 at 3:41 pm

function so_38057349_woocommerce_cart_subtotal( $cart_subtotal, $compound, $cart ) {
if( $cart->subtotal == 0 ){
$cart_subtotal = __( ”, ‘yourtheme’ );
}
return $cart_subtotal;
};
add_filter( ‘woocommerce_cart_subtotal’, ‘so_38057349_woocommerce_cart_subtotal’, 10, 3 );

// define the woocommerce_order_amount_total callback
function so_38057349_woocommerce_order_amount_total( $order_total ) {
if( WC()->cart->get_total() == 0 ){
$order_total = __( ‘Procede to checkout to see your total’, ‘yourtheme’ );
}
return $order_total;
};
add_filter( ‘woocommerce_cart_totals_order_total_html’, ‘so_38057349_woocommerce_order_amount_total’ );
add_filter( ‘woocommerce_cart_item_price’, ‘__return_false’ );
add_filter( ‘woocommerce_cart_item_subtotal’, ‘__return_false’ );

This is the code that i’m currently using. I had to manually change the prices to zero in in order for it call for the array $order_total. That way it would return “Proceed to checkout to see your total.” I’m no coder by any means but this seems like a wonky method. Not sure if I could simply change the comparison operator to “>” instead of “==”. That way any number greater than 0 should return the same array.

As of right now, things seem ok other than my Cart still displays the Sub Totals price. I’m having a hard time getting that filtered out.

John September 6, 2018 at 3:48 pm

Update: changing the comparison operator to “!==” did the trick and removed the subtotal price altogether. I’m still not sure if this is a correct fix or some jumble that seemingly worked.

My last issue still unresolved is when you click on one of my products you will see “Item availability”. This is against Amazon’s terms when not using their API. I need to remove this before I get the boot from the affiliate program.

Ryan Grieco September 7, 2018 at 7:54 pm

Hi Jeroen,

Thank you for the helpful tips. Is there a way to hide a price on a specific product variation? For example, I have a variable product where one size has a price and the other cannot have one.

Jeroen Sormani September 13, 2018 at 9:23 am

Should be possible – though I haven’t tested it myself. I’d recommend starting with testing out the last code snippet and use a variation ID instead of the product ID. With a bit of luck that will work straight away.

If that doesn’t work you’d likely want to look into filters specifically for variation product prices.

Vale September 12, 2018 at 11:48 pm

Helped me a lot!
Thank you

Ben September 18, 2018 at 12:18 am

I like the snippet for hiding the price from guests, is there any way to hide the add to cart button and replace the prices with “login to view prices” text as well? Every other snippet I’ve found that does all of that doesn’t hide the price from the search bar but yours does.

Jeroen Sormani October 11, 2018 at 9:05 pm

Hi Ben,

You should be able to do this by entering the text within the `return ‘YOUR TEXT’;` instead of returning a empty string.

Cheers,
Jeroen

Ben October 11, 2018 at 4:58 pm

Hi Jeroen,

First of all thanks for your blogs. They are great!

quick question; would your little script: “Hiding prices in specific categories” also work when I have a product already in another category?

So for example the product is already in a category called “electronics” and I create a new category called “hide price”

will it hide the price of that product if I include the “hide price” category in your script?

Jeroen Sormani October 11, 2018 at 9:03 pm

Hi Ben,

Yes, this should work right out of the box with the script.

Cheers,
Jeroen

JUAN FURLAN October 17, 2018 at 10:57 am

Thanks a lot.

Jeraldine November 15, 2018 at 4:22 pm

Thanks Jeroen!

I’m interested about your snipet Hide price for a specific product but unfortunatly it doesn’t work for me 🙁
My product give the price “From… to…” given from Measurment price calculator woo plugin.
Is there a simple hook to achieved this?

Jeroen Sormani November 16, 2018 at 10:07 am

You could try it with a higher priority, but if that doesn’t work it’d require some other code to deactivate that plugin’s price output.

Chrysostomos January 14, 2019 at 12:27 pm

Hello and thank you for your help through your article, can I ask how can I hide prices in specific categories and for a specific user in the same time ?

Thank you

Adalberto Pérez February 20, 2019 at 8:26 pm

This is valuable article, thank you!
If you decide to hide the price, you would probably want to hide the add to cart button, right? how would you do that?

Kim March 10, 2019 at 6:34 am

Hi Jeroen, thanks so much for your help.
I’ve added the code to functions.php and the css, however the subtotal and total are still showing on the cart and checkout page.

Is there another way of removing these please?

Cheers

Jeroen Sormani March 20, 2019 at 4:37 pm

Hi Kim,

Make sure to clear your caches when making changes to the CSS, often times this is what is stopping changes from showing.
It could also be your theme is has different classes assigned to the table/fields causing them to not be hidden on the cart/checkout.

Ioannis March 20, 2019 at 1:39 pm

Hello guys, quick question if I remove the price for all products and add to cart button (say I want my woocommerce to only display as catalogue) do I need to remove the structured data for the price as well or there is no fear to get penalized by google?

edo April 14, 2019 at 12:34 pm

Hi, hello
How to remove the line (dash) from regular price in product and single product page?

Thank you
Best regards
Edo

Marc May 12, 2019 at 4:13 pm

Hi Jeroen Sormani

Thanks so much for your blogs!

I am applying the snippet to hide the price of certain products but I would like to hide only on single product page and leave the price in the shop,

do you think it’s possible by modifying something in the snippet

thanks again

add_filter( ‘woocommerce_get_price_html’, function( $price, $product ) {

$hide_for_products = array( 7822 );
if ( in_array( $product->get_id(), $hide_for_products ) ) {
return ”;
}

return $price; // Return original price
}, 10, 2 );

Greg January 28, 2021 at 9:27 pm

Just wanted to say thanks for these snippets. The one that I needed and had eluded me until I found your site, was the one to hide prices on specific categories.

I did however want to show pricing in the cart and checkout, so I just simply removed the last two lines and that did the trick.

Excellent and thanks again! 🙂

Steven Hogenbosch March 17, 2021 at 10:57 am

Thanks Jeroen,

I was trying to hide the (regular) price when setting up a wholesale store so prices will only be shown to logged in (wholesale) users.

The snippet ‘Hiding prices for guest users’ did the trick when using Custom Product Layout in Flatsome in combination with the Woo Wholesale Prices Premium plugin.

Leave a Reply