【发布时间】:2021-02-17 00:26:05
【问题描述】:
在 WooCommerce 单品页面的 meta 部分,我需要提取一个标签 ID (135)。
我想查看一个简单产品中的所有标签,如果遇到要打印的 ID 为 135 的标签:
- 材质:皮革 (ID 135)
我正在尝试一些东西,但我无法获得该标签 ID
add_action('woocommerce_product_meta_end', 'wh_renderProductTagDetails');
function wh_renderProductTagDetails()
{
global $product;
$tags = get_the_terms($product->get_id(), 'product_tag');
//print_r($tags);
if (empty($tags))
return;
foreach ($tags as $tag_detail)
{
if ($tags (135)){
// echo '<p> Material: Leather</p>';
echo '<p> Material: ' . $tag_detail->name . '</p>';
}
}
}
有人可以指导我如何做到这一点吗?
【问题讨论】:
标签: php wordpress woocommerce tags product