【发布时间】:2016-10-31 00:19:28
【问题描述】:
我有一小段代码可以计算购物车总额(不含税)并在购物车总额低于 50 美元时输出免费送货加售。
// 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 以便它根据动态购物车总数工作?
【问题讨论】:
标签: php ajax wordpress woocommerce