예술 총액에 특정 금액을 기준으로 수수료를 추가하려고합니다. 카트 총계가 총 "$$$"금액과 같거나 더 큰지를 보여주고 싶습니다. 수수료를 추가하십시오. 그렇지 않으면 추가하지 마십시오.WooCommerce의 특정 장바구니 합계를 기준으로 수수료를 추가하십시오.
나는 총액을 더하는 방법을 알고 있지만, 달러 금액 미만인지 확인하고 있다고 생각하지 않는다.
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');
내가 뭘 잘못하고 있니? 이 훅은 카트 총 계산하기 전에 해고로 WC()->cart->total
항상 0
을 반환 woocommerce_cart_calculate_fees
액션 후크에서
'else'부분이 '아래'입니다. – Reigel