Add custom items to LD JSON Schema

This snippet will allow you to add custom items to LD JSON Schema generated by WooCommerce

add_filter('woocommerce_structured_data_product_offer',function ($foo) {
                if ( ! isset( $product ) ) {
                        global $product;
                }
                if ( ! is_a( $product, 'WC_Product' ) ) {
                        return;
                }
                if ( '' !== $product->get_price() ) {
                        $foo['itemCondition'] = 'https://schema.org/NewCondition';
                        $foo['description'] = $product->get_short_description().' '.$product->get_description();
                }
                return $foo;
});

 

Orignally from  WC Issue 15045


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.