[英]Display custom price suffix on WooCommerce discounted products
我有一家 WooCommerce 商店,並且正在使用“Woocommerce 的高級動態定價”插件。 我需要使用這個插件,因為我設置了折扣結構
百分比折扣已應用於商店中的所有產品。 原始價格被划掉,旁邊是新價格。
在此處輸入圖片說明
我想在新價格旁邊顯示一個后綴,上面寫着“inc VAT”,以表明價格包含增值稅。
我試過這個代碼,它似乎適用於沒有折扣的產品,但不適用於打折產品。
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>
您可以使用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 文件中。 測試和工作。
有關的:
您可以使用以下過濾器添加后綴。
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 設置添加后綴。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.