【发布时间】:2021-02-05 11:13:05
【问题描述】:
我使用的是 Wordpress 购物主题,它将产品详细信息(价格、颜色等)显示为 json 脚本,但我至少需要将价格显示为文本。开发人员不是很有帮助,我的 php 知识仅限于没有,所以我希望这对这里的人来说是一个简单/快速的修复。 这是生成 json 的脚本部分:
if(is_array($product['skuAttr'])) {
$str_data['offers'] = [];
foreach ($product['skuAttr'] as $k => $attr) {
$str_data['offers'][] = [
"@type" => "Offer",
"url" => $this_url . '?sku=' . $k,
"priceCurrency" => $product['currency'],
"price" => $attr['_salePrice_nc'],
"priceValidUntil" => date('Y-m-d',
strToTime('today + 30 days')
),
"name" => $itemmeta['name'],
"availability" => $attr['isActivity'] ? "https://schema.org/InStock" : "https://schema.org/OutOfStock",
"itemCondition" => "https://schema.org/NewCondition"
];
$min_saleprice = min($attr['_salePrice_nc']); // that's mine
}
}
...以后:
<script type="application/ld+json">
<?php echo json_encode($str_data); ?>
</script>
$min_saleprice 是我的想法,后来我也附和了,当然,它破坏了网站。
<?php echo $min_saleprice; ?> /// not a chance
那么,如何在文档后面显示_salePrice_nc? 谢谢。
如果重要的话,我正在使用最新的 Wordpress 5.6.1、PHP 7.2、nGinx,我需要它来验证 Pinterest 上的产品,它的爬虫不够聪明,无法从脚本中获取价格,我认为它必须在页面中以纯文本形式找到它。 enter image description here
【问题讨论】:
-
忘了说json脚本生成正常。