WooCommerce: Hide Product Price & Stock From Google

The WooCommerce Plugin is also developed with SEO in mind and provides your website with the schema markup for products (as well as other microdata useful for search engines).

This means by default your products are going to show on Google together with other data such as review stars, stock status, number of reviews and – you saw that coming – the product price.

In certain case scenario, however, you may want to hide WooCommerce product prices from Google search results (and all the other search engines of course). For example, because your prices are only visible to logged in users; or maybe because you don’t want to display your prices until potential customers go to your website and read all the product benefits as opposed to having them make a price-only decision.

Either way, let’s see how it’s done. And once again, it’s one line of code. Enjoy!

These are 3 products for sale on WooCommerce.com. By default, their price is visible within the search result. In this tutorial we’ll see how to hide it!

PHP Snippet: Remove WooCommerce Product Prices From Google Search Results

/**
 * @snippet       Hide Price & Stock @ Google
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli, BusinessBloomer.com
 * @testedwith    WooCommerce 6
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_structured_data_product_offer', '__return_empty_array' );

That’s it!

Please note, here’s the full code from WooCommerce core in case you want to manipulate it in a more specific way e.g. only the price:

if ( '' !== $product->get_price() ) {
	// Assume prices will be valid until the end of next year, unless on sale and there is an end date.
	$price_valid_until = gmdate( 'Y-12-31', time() + YEAR_IN_SECONDS );

	if ( $product->is_type( 'variable' ) ) {
		$lowest  = $product->get_variation_price( 'min', false );
		$highest = $product->get_variation_price( 'max', false );

		if ( $lowest === $highest ) {
			$markup_offer = array(
				'@type'              => 'Offer',
				'price'              => wc_format_decimal( $lowest, wc_get_price_decimals() ),
				'priceValidUntil'    => $price_valid_until,
				'priceSpecification' => array(
					'price'                 => wc_format_decimal( $lowest, wc_get_price_decimals() ),
					'priceCurrency'         => $currency,
					'valueAddedTaxIncluded' => wc_prices_include_tax() ? 'true' : 'false',
				),
			);
		} else {
			$markup_offer = array(
				'@type'      => 'AggregateOffer',
				'lowPrice'   => wc_format_decimal( $lowest, wc_get_price_decimals() ),
				'highPrice'  => wc_format_decimal( $highest, wc_get_price_decimals() ),
				'offerCount' => count( $product->get_children() ),
			);
		}
	} else {
		if ( $product->is_on_sale() && $product->get_date_on_sale_to() ) {
			$price_valid_until = gmdate( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() );
		}
		$markup_offer = array(
			'@type'              => 'Offer',
			'price'              => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ),
			'priceValidUntil'    => $price_valid_until,
			'priceSpecification' => array(
				'price'                 => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ),
				'priceCurrency'         => $currency,
				'valueAddedTaxIncluded' => wc_prices_include_tax() ? 'true' : 'false',
			),
		);
	}

	$markup_offer += array(
		'priceCurrency' => $currency,
		'availability'  => 'http://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
		'url'           => $permalink,
		'seller'        => array(
			'@type' => 'Organization',
			'name'  => $shop_name,
			'url'   => $shop_url,
		),
	);

	$markup['offers'] = array( apply_filters( 'woocommerce_structured_data_product_offer', $markup_offer, $product ) );
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Hide Prices on the Shop & Category Pages
    Interesting WooCommerce customization here. A client of mine asked me to hide/remove prices from the shop page and category pages as she wanted to drive more customers to the single product pages (i.e. increasing the click-through rate). As usual, a simple PHP snippet does the trick. I never recommend to use CSS to “hide” prices, […]
  • WooCommerce: Add Prefix / Suffix to Product Prices
    Sometimes you may want to add a prefix or a suffix to your prices. It could be something like “From…”, “Only…”, “…tax free” and so on. The first good news is this is very easy to do with a WooCommerce filter (remember, filters change the value of an existing variable, while actions add content). The […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

20 thoughts on “WooCommerce: Hide Product Price & Stock From Google

  1. Hi Rodolfo
    We have B2B store and lots of products are bundle products. Simple products prices are not appearing on Google but bundle products are still appearing on Google.

    Could you please help. Does your code works for Bundle products as well?

    We use WooCommerce Bundle plugin from WooCommerce market place.

    Please your help much appreciated.

    Many thanks
    Naimish

    1. I’d say it works for all product types. Have you tested it?

  2. Worked perfectly! Thank you so much for sharing this content!

  3. Hi
    Thank you for this helpful post!
    I have added the code in the functions.php file and got the webpage indexed by Google. But the price is still visible.
    What happens next? Is there anything else I have to do to maked the price hidden when searching on Google?

    Regards Malin

    1. Hello Malin, Google will take its time to remove the price from their index – maybe check again in a few days?

  4. Hi will this script works for “simple” products with regular price?

  5. Hey Rodolfo,

    I’ve followed your instructions, then instructed Google to re-index my pages which Google did (I submitted a sitemap in my Google webmasters account), but the price of this particular product is still visible in Google search results:

    https://tinyurl.com/2p8t2keh

    The source code of the cached version of the page however does NOT contain a price.

    What is your take on this? Am I missing something here?

    Thanks & cheers, Danny

    1. Uhm, not entirely sure. The other product prices got hidden?

  6. Hi Rodolfo and thanks a lot for your great help.
    I tried that, but of course I suppose I need to wait for some time to check the result, right?

  7. 1) Does this affect seo for google?

    2) would this work with the theme flatsome and yoast seo

    3) I would rather google know its there but just not show it, does this code do that? because am scared the empty array part might be telling google I have no prices, so something like hidden would be better no? I could be completely wrong as I know nothing about code. Thanks for all your help and keep up the good work friend

    1. 1) Yes of course, you’re hiding something Google wants to know
      2) Sure. Give it a go?
      3) We can’t hide things on Google. We can only pass them an empty value like in this case

  8. Hi Rodolfo!
    Does this work with stock status also?
    We wanted to hide stock status from google, could you help with it?

    Thanks and best regards

    1. Hi Aziz, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. Hi, will this work for prices showing up in google image search result? Like this for example here: https://i.ibb.co/zbVGmMt/fsegfs.png

    If so, how long should I wait for those prices to disappear? Cause many of my products prices are showing up like that and I need them to be removed.

    Thank you!

    1. Yes. It’ll take as long as Google wants unfortunately

  10. Hi Rodolfo

    I’d like to now how to add the brand for a woocommerce product, such that it satisfies the structured data schema.

    I know there are plugins for this, but in my case I only have one brand.

    How about a tutorial on how to achieve this? please

    All the best
    Mark

    1. Hey Mark, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *