Missing field ‘hasMerchantReturnPolicy’ (in ‘offers’)

#672875
Viewing 3 replies - 1 through 3 (of 3 total)
  • Alhan
    Rank Math free

    Hello,

    Thank you for your query, and we are so sorry about the trouble this must have caused.

    Please try the code provided below to see if that works for you ?

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    
        // Helper function to ensure array keys exist
        function set_nested_array_value(&$array, $path, $value) {
            $temp = &$array;
            foreach ($path as $key) {
                $temp = &$temp[$key];
            }
            $temp = $value;
        }
    
        // Helper function to create a schema section
        function create_schema_section($type, $properties = []) {
            $section = ['@type' => $type];
            foreach ($properties as $key => $value) {
                $section[$key] = $value;
            }
            return $section;
        }
    
        // Add return policy
        $returnPolicy = create_schema_section('MerchantReturnPolicy', [
            'applicableCountry' => 'US',
            'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow',
            'merchantReturnDays' => 30,
            'returnMethod' => 'https://schema.org/ReturnByMail',
            'returnFees' => 'https://schema.org/FreeReturn'
        ]);
        set_nested_array_value($entity, ['offers', 'hasMerchantReturnPolicy'], $returnPolicy);
    
        // Add shipping details
        $shippingDetails = create_schema_section('OfferShippingDetails', [
            'shippingRate' => create_schema_section('MonetaryAmount', [
                'value' => 5,
                'currency' => 'USD'
            ]),
            'shippingDestination' => create_schema_section('DefinedRegion', [
                'addressCountry' => 'US'
            ])
        ]);
        $deliveryTime = create_schema_section('ShippingDeliveryTime', [
            'handlingTime' => create_schema_section('QuantitativeValue', [
                'minValue' => 1,
                'maxValue' => 2,
                'unitCode' => 'DAY'
            ]),
            'transitTime' => create_schema_section('QuantitativeValue', [
                'minValue' => 4,
                'maxValue' => 5,
                'unitCode' => 'DAY'
            ])
        ]);
        set_nested_array_value($shippingDetails, ['deliveryTime'], $deliveryTime);
        set_nested_array_value($entity, ['offers', 'shippingDetails'], $shippingDetails);
    
        return $entity;
    });

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Please ensure that you adjust the values in the code for applicableCountry , returnPolicyCategory , merchantReturnDays , returnMethod , returnFees , value , currency , addressCountry , minValue , maxValue , unitCode , minValue , maxValue , unitCode .

    You can also refer to the screenshot below, for what can be customised:

    screenshot

    The values can be customised as per your speciific needs and business rules.

    We hope that helps, and please don’t hesitate to get in touch if you have any other questions.

    Thank you.

    VHP
    Rank Math free

    Thank you.

    Hello,
    
    We are super happy that this issue is already resolved. 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://wordpress.org/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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Missing field ‘hasMerchantReturnPolicy’ (in ‘offers’)’ is closed to new replies.