Created
January 14, 2026 18:05
-
-
Save sybrew/ab23d387d309f192c3636eb4dfe099c0 to your computer and use it in GitHub Desktop.
Adds shippingDetails and hasMerchantReturnPolicy to WooCommerce product Schema.org structured data output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Don't include the PHP opening tag if PHP is already open. | |
| add_filter( | |
| 'woocommerce_structured_data_product_offer', | |
| function ( $markup_offer, $product ) { | |
| // Add shipping details. | |
| $markup_offer['shippingDetails'] = [ | |
| '@type' => 'OfferShippingDetails', | |
| 'shippingRate' => [ | |
| '@type' => 'MonetaryAmount', | |
| 'value' => '0', | |
| 'currency' => get_woocommerce_currency(), | |
| ], | |
| 'shippingDestination' => [ | |
| '@type' => 'DefinedRegion', | |
| 'addressCountry' => WC()->countries->get_base_country(), | |
| ], | |
| 'deliveryTime' => [ | |
| '@type' => 'ShippingDeliveryTime', | |
| 'handlingTime' => [ | |
| '@type' => 'QuantitativeValue', | |
| 'minValue' => 0, | |
| 'maxValue' => 1, | |
| 'unitCode' => 'd', | |
| ], | |
| 'transitTime' => [ | |
| '@type' => 'QuantitativeValue', | |
| 'minValue' => 1, | |
| 'maxValue' => 5, | |
| 'unitCode' => 'd', | |
| ], | |
| ], | |
| ]; | |
| // Add merchant return policy. | |
| $markup_offer['hasMerchantReturnPolicy'] = [ | |
| '@type' => 'MerchantReturnPolicy', | |
| 'applicableCountry' => WC()->countries->get_base_country(), | |
| 'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow', | |
| 'merchantReturnDays' => 30, | |
| 'returnMethod' => 'https://schema.org/ReturnByMail', | |
| 'returnFees' => 'https://schema.org/FreeReturn', | |
| ]; | |
| return $markup_offer; | |
| }, | |
| 10, | |
| 2, | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment