我在 WooCommerce 单一产品页面上添加价格后缀(并且仅在那里,不在循环中!)。
我使用以下内容:
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ) {
if( is_product() ) {
$price = $price . ' <small>incl. tax</small>';
}
return apply_filters( 'woocommerce_get_price', $price );
}
不过,这也给产品页面的Up-Sells添加了价格后缀(我说的不是相关产品,而是Up-Sells)。
如何排除追加销售的价格后缀?
I tried:
if( is_product() && !$woocommerce_loop['name'] == 'up-sells' )
但追加销售仍会显示后缀。
在你的代码中$woocommerce_loop
没有定义
不进行比较,而是进行相反的操作,仅将其应用于空值
所以你得到:
function filter_woocommerce_get_price_html( $price, $product ) {
global $woocommerce_loop;
if ( is_product() && $woocommerce_loop['name'] == '' ) {
$price .= ' <small> incl. tax</small>';
}
//return $price;
return apply_filters( 'woocommerce_get_price', $price );
}
add_filter( 'woocommerce_get_price_html', 'filter_woocommerce_get_price_html', 10, 2 );
OR use
function filter_woocommerce_get_price_html( $price, $product ) {
global $woocommerce_loop;
if ( is_product() && $woocommerce_loop['name'] !== 'related' && $woocommerce_loop['name'] !== 'up-sells' ) {
$price .= ' <small> incl. tax</small>';
}
//return $price;
return apply_filters( 'woocommerce_get_price', $price );
}
add_filter( 'woocommerce_get_price_html', 'filter_woocommerce_get_price_html', 10, 2 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)