As a store owner or digital marketer, prices are your best friend and your worst enemy — depending on where and how you use them. While generally, it’s a good idea to display prices upfront, sometimes the marketing strategy dictates otherwise.
There’s an interesting use case one of our clients came to us with recently. They wanted to hide prices on the shop and category pages of their WooCommerce store, prompting the customer to click on a product to find out its price.
We saw in a previous post how to hide products from certain categories on the shop page. In this post, we will see how to hide the prices on the category archive pages and shop page.
Hide prices on category archive pages:
The above image shows the ‘Urban’ category archive page. The prices are displayed below the product title.
Getting this done is very simple, actually. All you need is less than 10 lines of PHP code, explained in the snippet below:
/** * Snippet 1: Hide prices on all categories * Created by: Tyche Softwares */ function tyches_hide_prices_on_all_categories( $price, $product ) { if ( is_product_category() ) { return ''; // Empty string = no price! } return $price; } add_filter( 'woocommerce_get_price_html', 'tyches_hide_prices_on_all_categories', 10, 2 );
In this example, we have used the WooCommerce filter ‘woocommerce_get_price_html‘ which is located in the file – abstract-wc-product.php.
This function accepts 2 parameters – $price & $product. We can modify our price from here and return it. If we want to hide the price for all the category archive pages, we use the function is_product_category(). This function checks if the current page is a product category or tags archive page and if it is then set the $price as blank on all the product category & tags archive pages.
Here is the ‘Urban’ category archive page after hiding the prices –
![How to Hide Prices on WooCommerce Shop and Category Pages 2 Hide Prices on all category pages](https://media.tychesoftwares.com/wp-content/uploads/2019/01/blog-2.png)
This function is only for the display purpose and won’t affect the actual prices of the products.
If you want to hide the price of a specific category only, then you can pass the slug of the category to the is_product_category() function. Here is an example –
/** * Snippet 1: Hide prices on all categories * Created by: Tyche Softwares */ function tyches_hide_prices_on_all_categories( $price, $product ) { if ( is_product_category('urban') ) { return ''; // Empty string = no price! } return $price; } add_filter( 'woocommerce_get_price_html', 'tyches_hide_prices_on_all_categories', 10, 2 );
In this example, only the ‘Urban’ product category’s archive page will hide the prices. The price on other categories will be displayed.
You can also use the WorPress function is_tax() which returns true when the current page is a category or tags archive page. However, for the product categories, we will pass the ‘product_cat’ as a parameter to this function to identify it as a product category.
Here is the same example with is_tax() function-
/** * Snippet 1: Hide prices on all categories * Created by: Tyche Softwares */ function tyches_hide_prices_on_all_categories( $price, $product ) { if ( is_tax('product_cat', 'urban' ) ) { return ''; // Empty string = no price! } return $price; } add_filter( 'woocommerce_get_price_html', 'tyches_hide_prices_on_all_categories', 10, 2 );
Hide prices on Shop page:
The method to hide the price from the shop page is same as above. If we want to hide the price only on the shop page,we can use the function is_shop() to check if the current page is a shop page or not. If it is then we return the price as blank.
function tyches_hide_prices_on_all_categories( $price, $product ) { if ( is_shop() ) { return ''; // Empty string = no price! } return $price; } add_filter( 'woocommerce_get_price_html', 'tyches_hide_prices_on_all_categories', 10, 2 );
Here is the shop page after the prices are hidden –
![How to Hide Prices on WooCommerce Shop and Category Pages 3 Hide prices on shop page](https://media.tychesoftwares.com/wp-content/uploads/2019/02/shop-page.png)
If we want all the archive pages like shop page, category pages, tags pages to hide the prices, then we will just return the blank price without checking for any condition.
function tyches_hide_prices_on_all_categories( $price, $product ) { return ''; } add_filter( 'woocommerce_get_price_html', 'tyches_hide_prices_on_all_categories', 10, 2 );
Yes, that’s all there is to it! As usual, you need to add them to the active theme’s functions.php
file. You can refer to this post on our site that describes 5 ways to add custom code to WordPress website.
hello how to hide prices in products section
Hello,
I would like to hide all the prices in cart and checkout.
Is it possible?
Thanks
Thanks for this information, worked like a charm! Maybe consider adding instructions earlier on in the article about where exactly to add the code. I was lost until I read the very last line stating to add it in the
functions.php
file. All good now. 🙂I just wanted the prices hidden on the shop page and this worked perfect. The ugly “spread” of prices “$1.00 – $5,000.00” display style is soooo tacky. You’re great. Thank you!
I am looking for a way to hide the price of any product of a specific category on the shop page all other products of other categories should have their price displayed.