2017-12-02 133 views
2
  1. 我的產品的價格需要以「每平方英尺」結尾。我希望這隻適用於特定類別的產品,並且只在價格大於0時使用。除非價格爲零,否則在價格後添加文字,然後在WooCommerce中致電價格

  2. 當產品沒有列出價格時,我需要價格在沒有平方英尺文字的情況下說「要求價格」之後。

所以這裏是我在網上找到的開始,但他們沒有任何與他們相關的條件,所以他們一直適用於所有產品。

/* Display "Call for Price" instead of empty price */ 
add_filter('woocommerce_get_price_html', 'custom_price_message'); 
function custom_price_message($price) { 
    $vat = ' per sq. ft.'; 
    return $price . $vat; 
} 

/* Display "Call for Price" instead of empty price */ 
add_filter('woocommerce_empty_price_html', 'custom_call_for_price'); 
add_filter('woocommerce_variable_empty_price_html', 'custom_call_for_price'); 
add_filter('woocommerce_variation_empty_price_html', 'custom_call_for_price'); 
function custom_call_for_price() { 
    return 'Call for Price'; 
} 
+0

另一種甜蜜的事情是有「價格面議」的文字可點擊的「電話」鏈接,將調用一次點擊。這不是必要的,但只是一個獎金 –

回答

1
add_filter('woocommerce_get_price_html', 'custom_price_message'); 
function custom_price_message($price) { 
if(!empty($price)){ 
    $vat = 'Your Text Here'; 
    return $price . $vat; 
}else{ 
    return 'CALL FOR PRICE'; 
} 
} 

我希望這個作品。

+0

非常感謝。這是朝着正確方向邁出的一步,但我現在只需要添加一個條件,使其僅適用於某個產品類別。 –

+0

請投我的答案,如果有幫助@LukeBaumann –

+0

我投了票,但我的名聲低於15(新帳戶),所以它不會被看到,直到它更高 –

0

謝謝你們的幫助。我同時使用你的代碼串的,這裏是我想出了:

add_filter('woocommerce_get_price_html', 'custom_price_message'); 

function custom_price_message($price) { 

if (!has_term('stone', 'product_cat')) { 
    return $price; 

} elseif (!empty($price)){ 
    $vat = ' per ft<sup>2</sup>'; 
    return $price . $vat; 

}else{ 
    return 'Call for Price'; 
} 
} 
+0

對不起,帖子。我一直在努力研究如何更改上面的代碼以適用於多個術語。我希望同樣的規則適用於另一個產品類別「殘餘物」以及「寶石」。任何幫助將會很糟糕! –