Advertisement
jaideep06

return and shipping

Jul 1st, 2024
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
  2.     if ( empty( $data['richSnippet'] ) || ! in_array( $data['richSnippet']['@type'], [ 'Product', 'ProductGroup' ] ) ) {
  3.         return $data;
  4.     }
  5.  
  6.     $data['shippingDetails'] = [
  7.         '@context'     => 'https://schema.org/',
  8.         '@type'        => 'OfferShippingDetails',
  9.         '@id'          => '#shipping_policy',
  10.         'deliveryTime' => [
  11.             '@type'        => 'ShippingDeliveryTime',
  12.             'handlingTime' => [
  13.                 '@type'    => 'QuantitativeValue',
  14.                 'minValue' => 0,
  15.                 'maxValue' => 1,
  16.                 'unitCode' => 'DAY',
  17.             ],
  18.             'transitTime' => [
  19.                 '@type'    => 'QuantitativeValue',
  20.                 'minValue' => 1,
  21.                 'maxValue' => 3,
  22.                 'unitCode' => 'DAY'
  23.             ],
  24.         ],
  25.         'shippingRate' => [
  26.             '@type'    => 'MonetaryAmount',
  27.             'value'    => 2000,
  28.             'currency' => 'SEK',
  29.         ],
  30.         'shippingDestination' => [
  31.             '@type' => 'DefinedRegion',
  32.             'addressCountry' => 'SE'
  33.         ]
  34.     ];
  35.     $data['hasMerchantReturnPolicy'] = [
  36.         '@context'     => 'https://schema.org/',
  37.         '@type'        => 'MerchantReturnPolicy',
  38.         '@id'          => '#merchant_policy',
  39.         'applicableCountry' => 'SE',
  40.         'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow',
  41.         'merchantReturnDays' => 14,
  42.         'returnMethod' => 'https://schema.org/ReturnByMail',
  43.         'returnFees' => 'https://schema.org/FreeReturn'
  44.     ];
  45.     if ( 'Product' ===  $data['richSnippet']['@type'] ) {
  46.         $data['richSnippet']['offers']['shippingDetails'] = [ '@id' => '#shipping_policy' ];
  47.         $data['richSnippet']['offers']['hasMerchantReturnPolicy'] = ['@id' => '#merchant_policy'];
  48.         return $data;
  49.     }
  50.  
  51.     if ( empty( $data['richSnippet']['hasVariant'] ) ) {
  52.         return $data;
  53.     }
  54.  
  55.     foreach ( $data['richSnippet']['hasVariant'] as $key => $value ) {
  56.         if ( empty( $value['offers'] ) ) {
  57.             continue;
  58.         }
  59.  
  60.         $data['richSnippet']['hasVariant'][ $key ]['offers']['shippingDetails'] = [ '@id' => '#shipping_policy' ];
  61.         $data['richSnippet']['hasVariant'][ $key ]['offers']['hasMerchantReturnPolicy'] = [ '@id' => '#merchant_policy' ];
  62.     }
  63.  
  64.     return $data;
  65.  
  66. }, 99, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement