2014-09-22 3 views
0

12 (수량)에 할인을 적용하고 12 (수량) 미만으로 할인을 제거하고 싶습니다. 20 % 할인 쿠폰 코드 ('genew')를 만들었습니다. 장바구니 페이지 (우연한 상거래)의 장바구니 버튼을 클릭 할 때 쿠폰 코드를 적용하고 삭제했습니다. 쿠폰 코드 제거 기능은 누군가가 장바구니 업데이트 버튼을 두 번 클릭 할 때만 작동합니다. 한 번 클릭하면 쿠폰 코드가 제거되지 않습니다. 여기 장바구니 페이지의 업데이트 장바구니 버튼을 처음 클릭하면 쿠폰 코드가 제거되지 않습니다. woocommerce

내가 function.php에 사용하고 기능입니다

add_action('woocommerce_before_cart_table', 'discount_coupon'); 
function discount_coupon() { 
global $woocommerce; 
global $count_cart_quantity; 
if ($count_cart_quantity >= 12) { 
$coupon_code = 'genew'; 
if (!$woocommerce->cart->add_discount(sanitize_text_field($coupon_code))) { 
    $woocommerce->show_messages(); 
} 

} 

if ($count_cart_quantity < 12 && $count_cart_quantity > 1) { 
$coupon_code = 'genew'; 
if (!$woocommerce->cart->remove_coupons(sanitize_text_field($coupon_code))) { 
    $woocommerce->show_messages(); 
} 

} 

}

당신은 하나에, 포괄적 문이 조건문을 결합해야

답변

0

:

add_action('woocommerce_before_cart_table', 'discount_coupon'); 
function discount_coupon() { 
    global $woocommerce; 
    global $count_cart_quantity; 

    $coupon_code = 'genew'; 

    if ($count_cart_quantity >= 12) { 
     if (!$woocommerce->cart->add_discount(sanitize_text_field($coupon_code))) { 
      $woocommerce->show_messages(); 
     } 
    } 
    elseif ($count_cart_quantity < 12 && $count_cart_quantity > 1) { 
     if (!$woocommerce->cart->remove_coupons(sanitize_text_field($coupon_code))) { 
      $woocommerce->show_messages(); 
     } 
    } 
} 
+0

이 스크린 샷을 참조하십시오 . http://imgur.com/Nid02c7 – craig

+0

문제는 12 개 이하의 수량이 감소한 후에는 전체를 업데이트하지 않고 20 % 할인 된 가격입니다. 12 개 이하의 수량을 변경 한 후 처음으로 업데이트 버튼을 클릭하면 총 가격이 업데이트되지 않지만 두 번째 번에 업데이트 카트 버튼을 클릭하면 올바른 총계가 표시됩니다. – craig

관련 문제