OhhMuaOhhMua
  • Home
  • WordPress
    • Solutions & Troubleshooting
    • Installation & Setup
    • Themes & Plugins
    • Security
  • Tools
    • veo3 prompt generator
  • Our Team
  • Hosting
    • Best Web Hosting
    • Free Web Hosting
    • VPS Hosting
Reading: Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
Notification Show More
OhhMuaOhhMua
  • WordPress
  • Entry-level Builds
  • High-end Builds
  • Mid-range Builds
  • Hardware Tips
  • Software Tips
Search
  • Home
  • WordPress
    • Installation & Setup
    • Security
    • Solutions & Troubleshooting
    • Themes & Plugins
  • Tools
    • veo3 prompt generator
  • Our Team
    • Hosting
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

Admin (Nghia Vo)
Last updated: September 14, 2024 3:44 pm
Admin (Nghia Vo)
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!”

480520387 657957633334779 6814038772835954285 n
Admin (Nghia Vo)

Hi, I’m Nghia Vo: a computer hardware graduate, passionate PC hardware blogger, and entrepreneur with extensive hands-on experience building and upgrading computers for gaming, productivity, and business operations.
As the founder of Vonebuy.com, a verified ecommerce store under Vietnam’s Ministry of Industry and Trade, I combine my technical knowledge with real-world business applications to help users make confident decisions.

I specialize in no-nonsense guides on RAM overclocking, motherboard compatibility, SSD upgrades, and honest product reviews sharing everything I’ve tested and implemented for my customers and readers.

You Might Also Like

Headless vs Traditional WooCommerce: Which Architecture Wins?

Can AI Agents Safely Access Your WordPress Site?

Is WordPress Dead or Still Powering the Web in 2026?

WordPress 6.9.2 Disaster: Why You Should Never Auto-Update Immediately

Headless WordPress Explained: Is It Right for Your Site?

TAGGED:hasMerchantReturnPolicyshippingDetails
Share This Article
Facebook Twitter Email Print
By Admin (Nghia Vo)
Follow:
Hi, I’m Nghia Vo: a computer hardware graduate, passionate PC hardware blogger, and entrepreneur with extensive hands-on experience building and upgrading computers for gaming, productivity, and business operations. As the founder of Vonebuy.com, a verified ecommerce store under Vietnam's Ministry of Industry and Trade, I combine my technical knowledge with real-world business applications to help users make confident decisions. I specialize in no-nonsense guides on RAM overclocking, motherboard compatibility, SSD upgrades, and honest product reviews sharing everything I’ve tested and implemented for my customers and readers.
Leave a comment Leave a comment

Leave a Reply Cancel reply

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

Trending

How to Make Google Understand and Value Your Content
Solutions & Troubleshooting

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

June 5, 2025
WordPress 7.0 Finally Fixes 20 Years of Painful Collaboration Problems
Solutions & Troubleshooting

WordPress 7.0 Finally Fixes 20 Years of Painful Collaboration Problems

March 9, 2026
Protecting Your WordPress Site from File Upload Vulnerabilities
Solutions & Troubleshooting

Protecting Your WordPress Site from File Upload Vulnerabilities

September 26, 2024
Title and Meta Description Mismatch on Google
Solutions & Troubleshooting

Title and Meta Description Mismatch on Google[How to fix]

September 25, 2024
Share a countdown button to display a password in WordPress
Solutions & Troubleshooting

Share a countdown button to display a password in WordPress

September 11, 2024
headless vs traditional woocommerce site
Solutions & Troubleshooting

Headless vs Traditional WooCommerce: Which Architecture Wins?

March 19, 2026
Previous Next

You Might Also Like

HETZNER HOSTING
Solutions & Troubleshooting

Why Hetzner Might Not Be the Right Choice for Beginners

Admin (Nghia Vo) Admin (Nghia Vo) March 7, 2026
wordpress speed 2026
Solutions & Troubleshooting

WordPress Speed in 2026: The Only Hosting Checklist You Need

Admin (Nghia Vo) Admin (Nghia Vo) March 7, 2026
What Happens When Web Hosting Companies Get Acquired
Solutions & Troubleshooting

What Happens When Web Hosting Companies Get Acquired

Admin (Nghia Vo) Admin (Nghia Vo) March 6, 2026
wordpress shortcode 1
Solutions & Troubleshooting

WordPress Shortcodes: Complete Guide to Dynamic Content

Admin (Nghia Vo) Admin (Nghia Vo) March 4, 2026
Cannot Fetch Sitemap in Google Search Console
Solutions & Troubleshooting

Cannot Fetch Sitemap in Google Search Console

Admin (Nghia Vo) Admin (Nghia Vo) May 27, 2025
Discovered – Currently Not Indexed in Google Search Console
Solutions & Troubleshooting

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

Admin (Nghia Vo) Admin (Nghia Vo) May 25, 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
  • Editorial Standards
Welcome Back!

Sign in to your account

Lost your password?