OhhMuaOhhMua
  • Home
  • Hosting
    • Best Web Hosting
    • Free Web Hosting
    • VPS Hosting
  • WordPress
    • Solutions & Troubleshooting
    • Installation & Setup
    • Themes & Plugins
    • Security
  • Computer Tips
    • Gaming Errors & Solutions
    • PC Troubleshooting
    • Computer Hardware
  • Coupons & Deals
  • Contact Us
  • veo3 prompt generator
Reading: Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
Share
Notification Show More
Font ResizerAa
OhhMuaOhhMua
Font ResizerAa
  • Computer Tips
  • Hosting
  • WordPress
Search
  • Home
  • WordPress
    • Installation & Setup
    • Security
    • Solutions & Troubleshooting
    • Themes & Plugins
    • Troubleshooting
  • Hosting
    • Free Web Hosting
    • VPS Hosting
    • Best Web Hosting
  • Computer Tips
    • PC Troubleshooting
    • Gaming Errors & Solutions
    • Computer Hardware
  • Coupons & Deals
  • veo3 prompt generator
Have an existing account? Sign In
Follow US
Copyright © 2024 ohhmua. All rights reserved.
OhhMua > Blog > WordPress > Solutions & Troubleshooting > Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
Solutions & Troubleshooting

Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce

ohhmua
Last updated: September 14, 2024 3:44 pm
ohhmua
Share
6 Min Read
Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
SHARE

In Q4 2023, Google rolled out an update requiring e-commerce websites to include shipping and return information in search results. Specifically, the attributes hasMerchantReturnPolicy and shippingDetails in the product’s schema offer. Although this is not mandatory, it triggers quite an annoying warning in Search Console.

You can find more information at: Shipping and Returns Information – Google Search Central Blog

The code below supports:

  • Default WooCommerce schema
  • Yoast SEO
  • Rank Math
  • Schema Pro (Remember to update the settings to apply the new schema).
Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce

How to fix the hasMerchantReturnPolicy and shippingDetails error for WooCommerce

Insert the code below into wp-content/themes/{your-theme}/functions.php.

/*
 * hasMerchantReturnPolicy và shippingDetails
 * 
 * */
add_filter( 'woocommerce_structured_data_product_offer', 'devvn_woocommerce_structured_data_product_offer' );
add_filter( 'wpseo_schema_product', 'devvn_wpseo_schema_product' );
add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'devvn_rich_snippet_product_entity', 99 );
add_filter( 'wp_schema_pro_schema_product', 'devvn_wp_schema_pro_schema_product' );
function get_hasMerchantReturnPolicy(){
    return '{
    "@type": "MerchantReturnPolicy",
    "applicableCountry": "vi",
    "returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow",
    "merchantReturnDays": "7",
    "returnMethod": "https://schema.org/ReturnByMail",
    "returnFees": "https://schema.org/FreeReturn"
}';
}
function get_shippingDetails(){
    return '{
  "@type": "OfferShippingDetails",
  "shippingRate": {
    "@type": "MonetaryAmount",
    "value": "0",
    "currency": "VND"
  },
  "deliveryTime": {
    "@type": "ShippingDeliveryTime",
    "businessDays": {
        "@type": "OpeningHoursSpecification",
         "dayOfWeek": [
            "https://schema.org/Monday",
            "https://schema.org/Tuesday",
            "https://schema.org/Wednesday",
            "https://schema.org/Thursday",
            "https://schema.org/Friday"
        ]
    },
    "handlingTime": {
      "@type": "QuantitativeValue",
      "minValue": "0",
      "maxValue": "3",
      "samedaydelivery" : "Yes",
      "unitCode": "DAY"
       
    },
    "transitTime": {
      "@type": "QuantitativeValue",
      "minValue": "0",
      "maxValue": "3",
      "samedaydelivery" : "Yes",
      "unitCode": "DAY"
    }                   
  },
  "shippingDestination": [
    {
      "@type": "DefinedRegion",
      "addressCountry": "VN",
      "addressRegion": ["VN"]
    }
  ]
}';
}
function devvn_wpseo_schema_product($data){
    if(isset($data['offers'])){
        $hasMerchantReturnPolicy = get_hasMerchantReturnPolicy();
        $shippingDetails = get_shippingDetails();
        foreach ($data['offers'] as $key => $offer){
            if(!isset($offers['hasMerchantReturnPolicy']) && $hasMerchantReturnPolicy){
                $data['offers'][$key]['hasMerchantReturnPolicy'] = json_decode($hasMerchantReturnPolicy, true);
            }
            if(!isset($offers['shippingDetails']) && $shippingDetails){
                $data['offers'][$key]['shippingDetails'] = json_decode($shippingDetails, true);
            }
        }
    }
    return $data;
}
function devvn_rich_snippet_product_entity($entity){
    global $product;
    if(!is_singular('product') || !$product || is_wp_error($product)) return $entity;
    $hasMerchantReturnPolicy = get_hasMerchantReturnPolicy();
    $shippingDetails = get_shippingDetails();
    if(!isset($entity['offers']['hasMerchantReturnPolicy']) && $hasMerchantReturnPolicy){
        $entity['offers']['hasMerchantReturnPolicy'] = json_decode($hasMerchantReturnPolicy, true);
    }
    if(!isset($entity['offers']['shippingDetails']) && $shippingDetails){
        $entity['offers']['shippingDetails'] = json_decode($shippingDetails, true);
    }
    //Fix Rankmath pro
    if(isset($entity['hasVariant']) && $entity['hasVariant']){
        foreach ($entity['hasVariant'] as $k=>$productList){
            if(!isset($productList['offers']['hasMerchantReturnPolicy']) && $hasMerchantReturnPolicy){
                $entity['hasVariant'][$k]['offers']['hasMerchantReturnPolicy'] = json_decode($hasMerchantReturnPolicy, true);
            }
            if(!isset($productList['offers']['shippingDetails']) && $shippingDetails){
                $entity['hasVariant'][$k]['offers']['shippingDetails'] = json_decode($shippingDetails, true);
            }
        }
    }
    return $entity;
}
function devvn_wp_schema_pro_schema_product($schema){
    if(isset($schema['offers']) && apply_filters( 'wp_schema_pro_remove_product_offers', true )) {
        $hasMerchantReturnPolicy = get_hasMerchantReturnPolicy();
        $shippingDetails = get_shippingDetails();
        if (!isset($schema['offers']['hasMerchantReturnPolicy']) && $hasMerchantReturnPolicy) {
            $schema['offers']['hasMerchantReturnPolicy'] = json_decode($hasMerchantReturnPolicy, true);
        }
        if (!isset($schema['offers']['shippingDetails']) && $shippingDetails) {
            $schema['offers']['shippingDetails'] = json_decode($shippingDetails, true);
        }
    }
    return $schema;
}
function devvn_woocommerce_structured_data_product_offer($offers){
    $hasMerchantReturnPolicy = get_hasMerchantReturnPolicy();
    $shippingDetails = get_shippingDetails();
    if(!isset($offers['hasMerchantReturnPolicy']) && $hasMerchantReturnPolicy){
        $offers['hasMerchantReturnPolicy'] = json_decode($hasMerchantReturnPolicy, true);
    }
    if(!isset($offers['shippingDetails']) && $shippingDetails){
        $offers['shippingDetails'] = json_decode($shippingDetails, true);
    }
    return $offers;
}

In the code above, pay attention to the following parameters. Make sure to change them as needed, or you can use the default values provided:

In the get_hasMerchantReturnPolicy function, there are:

  • merchantReturnDays: The number of days for returns
  • returnFees: Return fee
  • returnMethod: Method of return => By default, the code uses return via email, within 7 days, and with no return fees.

In the get_shippingDetails function, there are:

  • shippingRate > value: The shipping cost
  • shippingRate > currency: The currency of the shipping cost
  • deliveryTime: Operating days for delivery
  • shippingDestination: Shipping country

Make sure to review and replace the values as needed. Or, you can use the default values provided.

Good luck!”

You Might Also Like

SEO in the Age of AI: How to Make Google Understand and Value Your Content

Cannot Fetch Sitemap in Google Search Console

Discovered – Currently Not Indexed in Google Search Console: What It Means & How to Fix It

Why 2 Backlinks per Article Might Be Killing Your SEO

What is Obsidian? Why Developers Love This Note-Taking App

TAGGED:hasMerchantReturnPolicyshippingDetails
Share This Article
Facebook Twitter Email Print
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Trending

5 Signs It's Time to Upgrade Your Computer 5
Computer Tips

5 Signs It’s Time to Upgrade Your Computer

July 24, 2023
WordPress Covers Every Website Type
Solutions & Troubleshooting

Blog, E-Commerce, or Forum? WordPress Covers Every Website Type!

April 29, 2025
How to Install WordPress on cPanel
Installation & Setup

How to Install WordPress on cPanel: A Beginner-Friendly Guide

April 24, 2025
GTA 6 50 Fan Discoveries You
Gaming Errors & Solutions

GTA 6: 50 Fan Discoveries You Should Know – Full Breakdown

May 9, 2025
How to Check Computer Power Supply
Computer Hardware

How to Check Computer Power Supply

July 29, 2023
Fake CAPTCHA Malware Targets Gamers Seeking Cracked Wukong Downloads
Gaming Errors & Solutions

Fake CAPTCHA Malware Targets Gamers Seeking Cracked Wukong Downloads – How to Stay Safe

September 24, 2024
Previous Next

You Might Also Like

Optimize WordPress
Solutions & Troubleshooting

Want Faster Load Times? Optimize WordPress This Way

May 16, 2025
My Google Discover traffic skyrocketed after I did these 10 things
Solutions & Troubleshooting

My Google Discover traffic skyrocketed after I did these 10 things

May 14, 2025
How to Add a Read More to Product Descriptions in WooCommerce
Solutions & Troubleshooting

How to Add a “Read More” and “Show Less” Button to Product Descriptions in WooCommerce

May 5, 2025
Optimized Pagination thumbnail
Solutions & Troubleshooting

How I Optimized Pagination and Skyrocketed Traffic

April 28, 2025
Previous Next
newsletter featured

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Follow US on Social Media

Facebook Youtube Steam Twitch Unity

Copyright © 2024 ohhmua. All rights reserved.

OhhMua

Information

  • About
  • Terms & Conditions
  • Privacy Policy
Welcome Back!

Sign in to your account

Lost your password?