2015-06-16 163 views
0

如果價格等於或高於50,000英鎊,我正在使用某項功能來取消購買產品的功能。Woocommerce返回虛假信息

我想補充一個消息,其中添加到購物車按鈕通常,說「這個產品是在£50,000 - 請與我們聯繫

add_filter('woocommerce_is_purchasable', 'disable_cart_for_over_fifty_k', 10, 2); 

function disable_cart_for_over_fifty_k($purchasable, $product) { 
    if($product->get_price() >= 50000) 
     return false; 
} 
+1

我認爲如果你對問題/問題更直接,你更有可能獲得幫助。你目前的實施不起作用嗎? – ekims

+0

http://stackoverflow.com/help/mcve –

回答

0

你可以有一個$message變量爲空true,幷包含一個消息(在HTML)爲假:

PHP

$message = ""; 
... 
function disable_cart_for_over_fifty_k($purchasable, $product){ 
    global $message; 
    if($product->get_price() >= 50000) { 
     $message = "<p class='errorMessage'>This product is over £50,000 - please contact us</p>"; 
     return false; 
    } 
} 

HTML(例如

... 
<?php echo $message; ?> 
<button id="addCart">Add Cart</button> 
... 

您還可以,如果你想隱藏「加入購物車」一起使用標誌,並選擇什麼echo

1

您可以在任何動作掛鉤上顯示消息。

add_action('woocommerce_single_product_summary', 'so_contact_notice_30876596', 25); 
function so_contact_notice_30876596(){ 
    global $product; 
    if($product->get_price() >= 50000){ 
     echo "this product is over £50,000 - please contact us"; 
    } 
} 
+0

這真的是正確的做法,應該是正確的答案。這幫了很多,謝謝! – MillerMedia