I am trying to remove the structured data
that Woocommerce adds to the product pages.
I did some research and found that WC_Structured_Data::generate_product_data()
generates the structured data markup. It's hooked in the woocommerce_single_product_summary
action hook in the woocommerce/templates/content-single-product.php
template file.
I tried by adding the following code to the functions.php
remove_action( 'woocommerce_single_product_summary', 'WC_Structured_Data::generate_product_data()', 60 );
So structured data wouldn't be added by Woocommerce, but it doesn't work…
Am I doing something wrong? Is there another way to do what I am trying to achieve?
Instead, you can use dedicated filter hook 'woocommerce_structured_data_product'
that is located in WC_Structured_Data
for generate_product_data()
method nulling the structured data output in single product pages:
add_filter( 'woocommerce_structured_data_product', 'structured_data_product_nulled', 10, 2 );
function structured_data_product_nulled( $markup, $product ){
if( is_product() ) {
$markup = [];
}
return $markup;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.