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!
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 ) );
}
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
I’d say it works for all product types. Have you tested it?
Worked perfectly! Thank you so much for sharing this content!
Excellent
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
Hello Malin, Google will take its time to remove the price from their index – maybe check again in a few days?
Hi will this script works for “simple” products with regular price?
Yes, definitely
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
Uhm, not entirely sure. The other product prices got hidden?
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?
Yep!
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) 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
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
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!
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!
Yes. It’ll take as long as Google wants unfortunately
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
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!