1

I want to provide special discount on cart items but want to apply right after the coupon OR when proceed to checkout is clicked.

Example:

The customer added an item in cart with total price $100 and he applied the coupon e.g 10%OFF. Now the total remaining cost is $90 and now I want to apply additional 30% discount which will be on remaining cost ($90).

I found this but it does partial job:

function custom_wc_add_fee() {
    WC()->cart->add_fee( 'Fee', -10 );
}
add_action( 'woocommerce_cart_calculate_fees','custom_wc_add_fee' );

First, it applies when the cart page is loaded. (whenever I need after coupon). Secondly, I'm unable to get the cart price so unable to apply percent discount. What I like about hook is that it adds a little description so customer knows what happened.

1

Put this code in your current theme function.php file. Set how many discount as per your require.

function add_extra_discount( $cart ) {

  $discount = $cart->subtotal * 0.3;

  $cart->add_fee( __( 'Extra Discount', 'twentyseventeen' ) , -$discount );

}
add_action( 'woocommerce_cart_calculate_fees', 'add_extra_discount' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.