我有一个WooCommerce商店,正在使用“ Woocommerce的高级动态定价”插件。我需要使用此插件,因为我已经设置了折扣结构
百分比折扣已应用于商店中的所有产品。原始价格与新价格相抵。
在此处输入图片描述
我想在新价格旁边显示一个后缀,显示“含增值税”,以表明该价格已包含增值税。
我尝试过此代码,该代码似乎适用于没有应用折扣的产品,但不适用于打折产品。
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ){
$price = $price . 'inc VAT' ;
return apply_filters( 'woocommerce_get_price', $price );}
有人知道我怎么能做到吗?
生成的HTML代码如下:
<div class="woosg-price">
<div class="woosg-price-ori">
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">£</span>262.00</span>
</del>
<ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-
currencySymbol">£</span>117.90</span></ins>
</div>
<div class="woosg-price-new"></div>
</div>
答案 0 :(得分:1)
您可以使用woocommerce_get_price_suffix
专用钩子,针对销售产品,例如:
add_filter( 'woocommerce_get_price_suffix', 'custom_price_suffix', 999, 4 );
function custom_price_suffix( $html, $product, $price, $qty ){
if ( $product->is_on_sale() ) {
return ' ' . __('inc VAT', 'woocommerce');
}
return $html;
}
或者也许是(由于Woocommerce插件的高级动态定价):
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 999, 2 );
function custom_price_suffix( $price_html, $product ){
if ( $product->is_on_sale() ) {
$price_html .= ' ' . __('inc VAT', 'woocommerce');
}
return $price_html;
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
相关:
答案 1 :(得分:0)
您可以使用以下过滤器添加后缀。
add_filter( 'woocommerce_get_price_suffix', 'swt_add_price_suffix', 99, 4 );
function swt_add_price_suffix( $html, $product, $price, $qty ){
$html .= ' inc VAT';
return $html;
}
或者您也可以使用以下代码。
add_filter( 'woocommerce_get_price_html', 'swt_add_price_suffix', 99, 2 );
function swt_add_price_suffix( $price, $product ){
$price = $price.' inc VAT';
return $price;
}
您可以按照以下步骤从WooCommerce设置中添加后缀。