如果購物車總額低於50美元,我有一小部分代碼可計算購物車總額(不含稅)並輸出免費送貨優惠。WooCommerce - 在Ajax更新後計算購物車總額
// Shipping Upsell
/**
* Checks the cart for the Total excluding taxes
* @param $total_required
* @return bool
*/
function qualifies_basedon_cart_total($total_required) {
/*
* We only want to run this on the cart or checkout page
* If the cart subtotal is less than $total_required for free shipping, return true
*/
if(is_cart() || is_checkout()) {
if(WC()->cart->subtotal_ex_tax < $total_required) {
return true;
}
}
// do nothing
return false;
}
function shipup(){
// tests if total is below $50 and displays upsell if query returns ture
if(qualifies_basedon_cart_total(50)) {
echo "<div class =\"shipup\"><h3>Free Shipping</h3>\n<p>Get free shipping on all orders over $50!</p></div>";
}
}
add_action ('woocommerce_cart_collaterals','shipup', 1);
代碼在初始頁面加載上面的偉大工程,但改變車頁面的數量並選擇「更新購物車」我有以上(在functions.php中)的代碼基於不調整後本身新購物車總數。
我相信更新購物車按鈕使用AJAX,我的代碼無法使用它。如何AJAXIFY我的代碼,以便它的基礎上動態購物車總計?
請,這是撿來的代碼沒有任何變化。這裏是你的鏈接,包括更新你的答案:https://gist.github.com/rours/637b722debac38037766;你有沒有測試過它?如果沒有,也可以說未經測試。 – LoicTheAztec