【发布时间】:2017-09-06 19:04:17
【问题描述】:
我正在尝试根据艺术总金额的特定金额添加费用。我想显示购物车总数是否等于或大于总“$$$”金额添加费用,否则不添加。
我知道这可以将其添加到总计中,但我认为它不会检查它是否低于美元金额。
function woo_add_custom_fees(){
$cart_total = 0;
// Set here your percentage
$percentage = 0.15;
foreach( WC()->cart->get_cart() as $item ){
$cart_total += $item["line_total"];
}
$fee = $cart_total * $percentage;
if ( WC()->cart->total >= 25 ) {
WC()->cart->add_fee( "Gratuity", $fee, false, '' );
}
else {
return WC()->cart->total;
}
}
add_action( 'woocommerce_cart_calculate_fees' , 'woo_add_custom_fees' );
add_action( 'woocommerce_after_cart_item_quantity_update', 'woo_add_custom_fees' );
我做错了什么?
【问题讨论】:
-
else部分是“下面”
标签: php wordpress woocommerce cart hook-woocommerce