gpt4 book ai didi

php - 在 Woocommerce 单个产品页面中显示特定产品标签的自定义内容

转载 作者:行者123 更新时间:2023-12-04 08:04:35 27 4
gpt4 key购买 nike

我使用以下内容在 WooCommerce 单个产品页面中添加自定义 html 或文本,经过简短说明:

function my_content( $content ) {
$content .= '<div class="custom_content">Custom content!</div>';

return $content;
}
add_filter('woocommerce_short_description', 'my_content', 10, 2);
如何在包含特定产品标签(不是产品类别)的产品页面上进行限制?

最佳答案

您可以使用 has_term() WordPress conditional function , 限制您的自定义内容仅显示具有特定产品标签的产品,如下所示(在您的产品标签术语的功能中定义):

add_filter('woocommerce_short_description', 'my_content', 10, 2);
function my_content( $content ) {
// Here define your specific product tag terms (can be Ids, slugs or names)
$product_tags = array( 'Garden', 'Kitchen' );

if( has_term( $product_tags, 'product_tag', get_the_ID() ) ) {
$content .= '<div class="custom_content">' . __("Custom text!", "") . '</div>';
}
return $content;
}
代码位于事件子主题(或事件主题)的 functions.php 文件中。它应该有效。

关于php - 在 Woocommerce 单个产品页面中显示特定产品标签的自定义内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66284818/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com