Hello,
We apologize for the issue you are facing with the WooCommerce product schema. Thank you for raising this concern.
To remove prices from the variants in the WooCommerce schema, you can use a custom code snippet similar to the one you used for the parent product. Here’s a code snippet that should help you achieve this:
/**
* Filter to remove prices from product variants in WooCommerce schema
*/
add_filter('rank_math/json_ld', function ($data, $jsonld) {
if (is_product() && isset($data['hasVariant'])) {
foreach ($data['hasVariant'] as &$variant) {
if (isset($variant['offers'])) {
unset($variant['offers']); // Remove offers (prices) from variants
}
}
}
return $data;
}, 99, 2);
You can add this code snippet to your theme’s rank-math.php file as mentioned in our documentation. This will ensure that the prices are removed from all product variants as well.
If you have any further questions or need additional assistance, please feel free to reply to this ticket, and a human agent from the Rank Math Support team will assist you further.
Thank you for your understanding!
Sources:
Remove All Schema from Product Category Pages » Rank Math
Thank you for the speedy response, but this has unfortunately not worked.
Is there some other process that needs to be completed – e.g. akin to a cache-flush – or should this work dynamically and immediately.
I would appreciate any assistance with this.
Regards
Dave
Hello,
Thank you for contacting Rank Math support.
The code already unsets the entire offers section for variants, but if you only want to remove the price field from offers for variants (rather than removing the entire offers section), you can adjust the code like this:
/**
* Filter to remove price from product variants in WooCommerce schema
*/
add_filter('rank_math/json_ld', function ($data, $jsonld) {
if (is_product() && isset($data['hasVariant'])) {
foreach ($data['hasVariant'] as &$variant) {
if (isset($variant['offers']['price'])) {
unset($variant['offers']['price']); // Remove price from offers in variants
}
}
}
return $data;
}, 99, 2);
You can follow this guide to add the code:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how that goes and don’t hesitate to get in touch if you have any other questions.
Thank you.
Hi Guys,
Any response here… ?
Please note this is not a Rank Math Free installation. The license just happens to be under the account of the SEO agency.
Regards
Dave
Hello,
If you remove the prices from the offers, you might as well just remove the offers entirely because the price is required to be inside the offer for the products to pass validation.
It’s also important to note that if you don’t have an offer or a review/aggregate rating on the products it won’t pass validation and it will flood the GSC property with errors about the Rich Snippets on your website.
Having said that, to remove the data from the variations for the offers you can add the following filter on your website:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if ( $data['richSnippet']['hasVariant'] ) {
foreach( $data['richSnippet']['hasVariant'] as $variation => $property ) {
if( $property['offers'] ) {
unset( $data['richSnippet']['hasVariant'][$variation]['offers'] );
}
}
}
return $data;
}, 99, 2);
Hope this helps solve your issues.
Don’t hesitate to get in touch if you have any other questions.
Ok and if i want to remove all OFFER snippet?
Hello @juliano-1048
We already explained in both replies above how you can handle the removal of the offers from the website.
If you need further assistance you need to open a ticket for your specific case on our forums.
Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.