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

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
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 Build Your Own eGPU for Your Laptop in 2025
Hardware Tips

How to Build Your Own eGPU for Your Laptop in 2025

July 27, 2025
Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce
Solutions & Troubleshooting

Fixing hasMerchantReturnPolicy and shippingDetails error for WooCommerce

September 14, 2024
Want to Protect Your Website
Security

Want to Protect Your Website? Never Do These 6 Things!

May 23, 2025
6 PC Components to Avoid When Building Your PC in 2025
Hardware Tips

6 PC Components to Avoid When Building Your PC in 2025

July 30, 2025
mATX Build Ideal for Small Apartments thumbnail
Mid-range Builds

Build Gaming: mATX Build Ideal for Small Apartments

July 19, 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
Previous Next

You Might Also Like

Optimize WordPress
Solutions & Troubleshooting

Want Faster Load Times? Optimize WordPress This Way

Admin (Nghia Vo) Admin (Nghia Vo) 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

Admin (Nghia Vo) Admin (Nghia Vo) May 14, 2025
WordPress Covers Every Website Type
Solutions & Troubleshooting

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

Admin (Nghia Vo) Admin (Nghia Vo) April 29, 2025
Optimized Pagination thumbnail
Solutions & Troubleshooting

How I Optimized Pagination and Skyrocketed Traffic

Admin (Nghia Vo) Admin (Nghia Vo) April 28, 2025
How to Pick the Ideal Blogging Platform for Your Needs
Solutions & Troubleshooting

How to Pick the Ideal Blogging Platform for Your Needs

Admin (Nghia Vo) Admin (Nghia Vo) April 1, 2025
Protecting Your WordPress Site from File Upload Vulnerabilities
Solutions & Troubleshooting

Protecting Your WordPress Site from File Upload Vulnerabilities

Admin (Nghia Vo) Admin (Nghia Vo) September 26, 2024
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?