Search the site:

Home Blog How to Hide Prices on WooCommerce Shop and Category Pages

How to Hide Prices on WooCommerce Shop and Category Pages

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 –

Hide Prices on all category pages
Hide Prices on all category pages

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 –

Hide prices on shop page
Hide prices on shop page

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.

 

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
2 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
RobertSneha Anand Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest
Notify of
Sneha Anand
Guest

Hello Team,

I want to hide woocommerce price both in shop page as well as product category but I want product price to be shown in a specific product page.
Kindly help.

Robert
Guest
Robert

Hi, I’m really having trouble finding a snippet that hides the prices on the single product page, but leaves them in tact on the shop and archive pages. Could you tell me how to do that?

from purchased

Subscribe for more offers