ill try to hook change the discount percentage based on 3 different
for example:
- if costumer spend >= 200.000 they wiil have 10% discount
- if cosutumer spend >= 350.000 they will have 15% discount
- if costumer spend >= 500.000 they will have 20% discount
the question is how can i apply this discount in the selected product? and how to make thats manual, I mean that discount work when costumer input voucher code in the available colomn?
this is my code so far
add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_total',
25, 1 );
function discount_based_on_total( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$total = $cart->cart_contents_total;
// Percentage discount (10%)
if( $total >= 200000 )
$discount = $total * 0.1;
if( $total >= 350000 )
$discount = $total * 0.15;
if( $total >= 500000 )
$discount = $total * 0.20;
$cart->add_fee( __('discount', 'woocommerce'), -$discount );
}