Shipping and Return Policy in Product Structured Data
Adds your shipping cost, delivery time and return policy to the product structured data WooCommerce outputs, which Google can show in shopping results.
Opens WPIDE on
Code
$wpide_schema_policy = array(
'country' => 'GB', // Two-letter country code you ship to.
'shipping_cost' => '3.95',
'handling_days' => array( 0, 1 ),
'transit_days' => array( 1, 3 ),
'return_days' => 30,
'free_returns' => true,
);
add_filter( 'woocommerce_structured_data_product', function ( $markup, $product ) use ( $wpide_schema_policy ) {
if ( empty( $markup['offers'] ) || ! $product->needs_shipping() ) {
return $markup;
}
$currency = get_woocommerce_currency();
$shipping = array(
'@type' => 'OfferShippingDetails',
'shippingRate' => array( '@type' => 'MonetaryAmount', 'value' => $wpide_schema_policy['shipping_cost'], 'currency' => $currency ),
'shippingDestination' => array( '@type' => 'DefinedRegion', 'addressCountry' => $wpide_schema_policy['country'] ),
'deliveryTime' => array(
'@type' => 'ShippingDeliveryTime',
'handlingTime' => array( '@type' => 'QuantitativeValue', 'minValue' => $wpide_schema_policy['handling_days'][0], 'maxValue' => $wpide_schema_policy['handling_days'][1], 'unitCode' => 'DAY' ),
'transitTime' => array( '@type' => 'QuantitativeValue', 'minValue' => $wpide_schema_policy['transit_days'][0], 'maxValue' => $wpide_schema_policy['transit_days'][1], 'unitCode' => 'DAY' ),
),
);
$returns = array(
'@type' => 'MerchantReturnPolicy',
'applicableCountry' => $wpide_schema_policy['country'],
'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow',
'merchantReturnDays' => $wpide_schema_policy['return_days'],
'returnMethod' => 'https://schema.org/ReturnByMail',
'returnFees' => $wpide_schema_policy['free_returns'] ? 'https://schema.org/FreeReturn' : 'https://schema.org/ReturnFeesCustomerResponsibility',
);
foreach ( $markup['offers'] as $i => $offer ) {
$markup['offers'][ $i ]['shippingDetails'] = $shipping;
$markup['offers'][ $i ]['hasMerchantReturnPolicy'] = $returns;
}
return $markup;
}, 10, 2 );
Notes
Describe your main market in $wpide_schema_policy, and keep the values true to your real offer or Google may ignore them.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.