WordPress-seo-补充shippingDetails等结构化数据JSON-LD兼谈作用

谷歌邮件通知:提示检测到 「商家列表」的结构化数据问题,具体在在 offers 结构化数据中,缺少「配送详情」、「商家退货政策」等字段。

Missing field “hasMerchantReturnPolicy” (in “offers”)

Missing field “shippingDetails” (in “offers”)

既然谷歌提示并且建议了,事关seo,就得解决。在此之前,先了解下什么是结构化数据JSON-LD。

* 什么是结构化数据JSON-LD

在电商产品页面中,结构化数据(Structured Data) 是指通过标准化格式(如 JSON-LD、Microdata 等)对产品核心信息进行标记的代码,目的是让搜索引擎、浏览器或其他工具能快速、准确地识别和理解页面中的关键内容(如产品名称、价格、库存等)。相当于给产品信息 “贴标签”,告诉机器 “这部分是价格”“那部分是用户评分”,从而让搜索引擎在展示搜索结果时,能更丰富地呈现产品信息(如显示价格、评分、库存状态等),提升页面在搜索中的吸引力,最终可能增加点击量和转化。

电商产品页面中常见的结构化数据类型,是基于国际通用的 Schema.org 标准(主流搜索引擎如谷歌、百度均支持),电商产品页面最常用的是 Product 类型。

它以 JSON 格式嵌入页面 <script> 标签中:

* 分析结构化数据JSON-LD常用工具

1:谷歌结构化数据测试工具

https://search.google.com/test/rich-results

2:Schema.org 验证器

https://validator.schema.org

上面这两个工具(需科学上网),如下图:可以更直观地分析结构化数据,还能检查错误

例如:上图错误提示表明,在 MerchantReturnPolicy 类型的对象中,你使用了 returnPolicy 属性,但 Schema.org 标准并未定义该属性,导致验证失败。

* 利用 WooCommerce 的 woocommerce_structured_data_product 钩子,手动添加缺失结构化数据JSON-LD


// 补充结构化数据中的 shippingDetails(全球配送+满50包邮)和 hasMerchantReturnPolicy
add_filter('woocommerce_structured_data_product', 'add_missing_structured_data_fields', 10, 2);
function add_missing_structured_data_fields($markup, $product) {
    // 支持简单产品和可变产品(可根据需要添加其他类型,如grouped/bundle等)
    $supported_types = array('simple', 'variable');
    if (!in_array($product->get_type(), $supported_types)) {
        return $markup;
    }

    // 准备要添加的通用字段
    // 1. 补充 shippingDetails(全球配送+满50包邮)
    $shipping_details = [
        '@type' => 'OfferShippingDetails',
        'shippingDestination' => [
            '@type' => 'DefinedRegion',
            'addressCountry' => 'ZZ' // 'ZZ' 表示全球配送(符合ISO 3166标准)
        ],
        // 运费规则:满50免运费,否则收取5美元
        'shippingRate' => [
            '@type' => 'MonetaryAmount',
            'value' => '5.00', // 基础运费
            'currency' => get_woocommerce_currency()
        ],
        'deliveryTime' => [
            '@type' => 'ShippingDeliveryTime',
            'handlingTime' => ['@type' => 'QuantitativeValue', 'value' => '1', 'unitCode' => 'DAY'],
            'transitTime' => ['@type' => 'QuantitativeValue', 'value' => '7-15', 'unitCode' => 'DAY']
        ]
    ];
    // 2. 补充满额免运费规则(移至 Offer 类型下)
    $eligible_volume = [
        '@type' => 'PriceSpecification',
        'minPrice' => '50.00',
        'maxPrice' => '0',
        'priceCurrency' => get_woocommerce_currency()
    ];

    $return_policy = [
        '@type' => 'MerchantReturnPolicy',
        'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow',
        'merchantReturnDays' => 30,
        'itemCondition' => 'https://schema.org/NewCondition',
        'returnMethod' => 'https://schema.org/ReturnByMail'
    ];


    // 区分单个报价和多个报价
    if (isset($markup['offers'])) {
        // 情况1:可变产品(offers是数字索引数组,包含多个变体报价)
        if (is_array($markup['offers']) && isset($markup['offers'][0]['@type']) && $markup['offers'][0]['@type'] === 'Offer') {
            foreach ($markup['offers'] as &$offer) {
                $offer['shippingDetails'] = $shipping_details;
                $offer['eligibleTransactionVolume'] = $eligible_volume;
                $offer['hasMerchantReturnPolicy'] = $return_policy;
            }
        }
        // 情况2:简单产品(offers是单个关联数组)
        else {
            $markup['offers']['shippingDetails'] = $shipping_details;
            $markup['offers']['eligibleTransactionVolume'] = $eligible_volume;
            $markup['offers']['hasMerchantReturnPolicy'] = $return_policy;
        }
    }

    return $markup;
}

* 用Schema.org 验证器进行验证

用谷歌的用 Search Console 工具还能优化网站在谷歌搜索中的表现:

比如上图,提示检测结果: handlingTime 和 transitTime 缺少可选字段 minValue 和 maxValue。然后按照提示逐步优化就行了。