Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sybrew/ab23d387d309f192c3636eb4dfe099c0 to your computer and use it in GitHub Desktop.

Select an option

Save sybrew/ab23d387d309f192c3636eb4dfe099c0 to your computer and use it in GitHub Desktop.
Adds shippingDetails and hasMerchantReturnPolicy to WooCommerce product Schema.org structured data output
<?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