嗨,我需要更改Wooccommerce 上所选产品的产品价格
我有这个功能
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 11, 2 );
function custom_price_html($price_html, $product){
if (is_product()) {
// here I change the product price or styling
}
}
问题是函数在产品页面上执行。。。也可以在页面底部的相关产品上显示。
如何仅识别当前产品价格?!
谢谢!
您可以在if语句中添加一个额外的检查,以避免更改相关产品循环的price html。
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 11, 2 );
function custom_price_html($price_html, $product){
global $woocommerce_loop;
if( is_product() && !$woocommerce_loop['name'] == 'related' ) {
// here I change the product price or styling
}
}