• Resolved Milan.Nikolic

    (@milannikolic)


    Hi,

    I was wondering, is there any option where I can change the schema JSON code for schema.org/Product? I am trying to change something in “offers” property on Product item. I was wondering how can I alter this in my theme?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • There is a filter called “woocommerce_structured_data_product_offer” that might do the trick for you if used in your child theme’s functions.php. It looks like it passes the $markup_offer as an array as well as the $product object. You could add a function to alter $markup_offer and return the changed values.

    I haven’t tested this, but I think you’d do something like this if the product ID you wanted to change was 5:

    
    function fix_my_product_offers_schema ($markup_offer, $product) {
      if ($product->get_id() == 5) {
        // make your changes to the offers markup here
      }
      return $markup_offer;
    }
    add_filter('woocommerce_structured_data_product_offer', 'fix_my_product_offers_schema', 10, 2);
    

    You could alter the conditional if you have more than one product to change, or leave it out if you want to change all products.

    Thread Starter Milan.Nikolic

    (@milannikolic)

    Thank you very much! This did the trick and I managed to do what I wanted.

    Thanks again for the help.

    That’s great! I’m glad you got it working.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change schema json code for Product.’ is closed to new replies.