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
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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 this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

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.

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

  1. 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?

  2. 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?

  3. 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

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

  5. 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

  6. 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? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.