Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @masouddarvishi1992,

    Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.

    Our developers are discussing this internally to get all the technical info correct and the best approach to possibly include this in the future as at the moment, these properties are not available in our plugin.

    Since this feature is still not available in the plugin, the only possible way would be to edit the following filter with the appropriate data for these properties so it gets included in the Product Schema as well: https://rankmath.com/kb/filters-hooks-api-developer/#change-post-schema-data

    We have created an example filter that would help add this data and it assumes that the refund policy is only applicable to the USA and that it has a 30-day refund period.

    The shipping rate section also assumes a flat fee of 5$ to ship within the United States.

    This would need to be changed according to the website specifications but it should be a good starting point:
    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) { // Return policy $entity['offers']['hasMerchantReturnPolicy']['@type'] = 'MerchantReturnPolicy'; $entity['offers']['hasMerchantReturnPolicy']['applicableCountry'] = 'US'; $entity['offers']['hasMerchantReturnPolicy']['returnPolicyCategory'] = 'https://schema.org/MerchantReturnFiniteReturnWindow'; $entity['offers']['hasMerchantReturnPolicy']['merchantReturnDays'] = 30; $entity['offers']['hasMerchantReturnPolicy']['returnMethod'] = 'https://schema.org/ReturnByMail'; $entity['offers']['hasMerchantReturnPolicy']['returnFees'] = 'https://schema.org/FreeReturn'; // Shipping details $entity['offers']['shippingDetails']['@type'] = 'OfferShippingDetails'; $entity['offers']['shippingDetails']['shippingRate']['@type'] = 'MonetaryAmount'; $entity['offers']['shippingDetails']['shippingRate']['value'] = 5; $entity['offers']['shippingDetails']['shippingRate']['currency'] = 'USD'; $entity['offers']['shippingDetails']['shippingDestination']['@type'] = 'DefinedRegion'; $entity['offers']['shippingDetails']['shippingDestination']['addressCountry'] = 'US'; return $entity; });

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

    Thread Starter masouddarvishi1992

    (@masouddarvishi1992)

    Thank you. Now he also wants this from me:

    Missing field “deliveryTime” (optional)

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @masouddarvishi1992,

    For the missing field “deliveryTime” error, you can modify the above filter and can add the following lines there:
    $entity['offers']['shippingDetails']['deliveryTime']['@type'] = 'ShippingDeliveryTime'; $entity['offers']['shippingDetails']['deliveryTime']['handlingTime']['@type'] = 'QuantitativeValue'; $entity['offers']['shippingDetails']['deliveryTime']['handlingTime']['minValue'] = 0; $entity['offers']['shippingDetails']['deliveryTime']['handlingTime']['maxValue'] = 1; $entity['offers']['shippingDetails']['deliveryTime']['handlingTime']['unitCode'] = 'DAY'; $entity['offers']['shippingDetails']['deliveryTime']['transitTime']['@type'] = 'QuantitativeValue'; $entity['offers']['shippingDetails']['deliveryTime']['transitTime']['minValue'] = 1; $entity['offers']['shippingDetails']['deliveryTime']['transitTime']['maxValue'] = 5; $entity['offers']['shippingDetails']['deliveryTime']['transitTime']['unitCode'] = 'DAY';

    Please make sure to change the values according to your website data.

    Hope that helps and please don’t hesitate to let us know if you have any other questions.

    Thank you.

    is there any ETA for this feature to become available in plugin?

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @aghalati,

    No, we don’t currently have any ETA on this feature. When we release an update with these updates we’ll let you know of the same.

    Thank you.

    Diosa-UK

    (@venus-hair-brighton)

    This solution works great with simple products – thank you. But the same warnings pop up as non-critical errors for product variations too.

    Is there a snippet that can get this schema to work when product type is variable please?

    (I’ve hunted around for some code to make it work on variations but my skills are limited and I just keep killing my website when I add it to the functions.php !)

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @venus-hair-brighton,

    Please replace the previous filter with the one given below:
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) { if ( empty( $data['richSnippet'] ) || ! in_array( $data['richSnippet']['@type'], [ 'Product', 'ProductGroup' ] ) ) { return $data; } $data['shippingDetails'] = [ '@context' => 'https://schema.org/', '@type' => 'OfferShippingDetails', '@id' => '#shipping_policy', 'deliveryTime' => [ '@type' => 'ShippingDeliveryTime', 'handlingTime' => [ '@type' => 'QuantitativeValue', 'minValue' => 0, 'maxValue' => 1, 'unitCode' => 'DAY', ], 'transitTime' => [ '@type' => 'QuantitativeValue', 'minValue' => 1, 'maxValue' => 3, 'unitCode' => 'DAY' ], ], 'shippingRate' => [ '@type' => 'MonetaryAmount', 'value' => 2000, 'currency' => 'SEK', ], 'shippingDestination' => [ '@type' => 'DefinedRegion', 'addressCountry' => 'SE' ] ]; $data['hasMerchantReturnPolicy'] = [ '@context' => 'https://schema.org/', '@type' => 'MerchantReturnPolicy', '@id' => '#merchant_policy', 'applicableCountry' => 'SE', 'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow', 'merchantReturnDays' => 14, 'returnMethod' => 'https://schema.org/ReturnByMail', 'returnFees' => 'https://schema.org/FreeReturn' ]; if ( 'Product' === $data['richSnippet']['@type'] ) { $data['richSnippet']['offers']['shippingDetails'] = [ '@id' => '#shipping_policy' ]; $data['richSnippet']['offers']['hasMerchantReturnPolicy'] = ['@id' => '#merchant_policy']; return $data; } if ( empty( $data['richSnippet']['hasVariant'] ) ) { return $data; } foreach ( $data['richSnippet']['hasVariant'] as $key => $value ) { if ( empty( $value['offers'] ) ) { continue; } $data['richSnippet']['hasVariant'][ $key ]['offers']['shippingDetails'] = [ '@id' => '#shipping_policy' ]; $data['richSnippet']['hasVariant'][ $key ]['offers']['hasMerchantReturnPolicy'] = [ '@id' => '#merchant_policy' ]; } return $data; }, 99, 2);

    This will add the properties to both simple and variable products.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Diosa-UK

    (@venus-hair-brighton)

    Amazing! Thank you so much for taking the time to look at this and resolve for both Simple and Variable products. Very impressed ?????

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @venus-hair-brighton,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on
    https://www.ads-software.com/support/plugin/seo-by-rank-math/reviews/#new-post

    about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Missing field “shippingDetails” (optional)’ is closed to new replies.