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

Want to Protect Your Website
Security

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

May 23, 2025
Script Hook V Critical Error Fix
Gaming Errors & Solutions

How to Fix Script Hook V Critical Error in GTA 5 [TESTED]

May 9, 2025
Why Your Computer Is Slowing Down
PC Troubleshooting

Why Your Computer Is Slowing Down — And the 5 Fixes Tech Pros Swear By

May 21, 2025
admin wordpress dashboard
Themes & Plugins

Introduction to the WordPress Dashboard: Features, Tools, and Navigation

April 25, 2025
How to Install and Use Google Analytics 4
Installation & Setup

How to Install and Use Google Analytics 4 (GA4) in 2025: A Step-by-Step Guide

April 21, 2025
Cannot Fetch Sitemap in Google Search Console
Solutions & Troubleshooting

Cannot Fetch Sitemap in Google Search Console

May 27, 2025
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
WordPress Covers Every Website Type
Solutions & Troubleshooting

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

April 29, 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?