I've got two coupons, one $10 and the other $5. I want to do next if the price is less than $50 and the customer enters a $10 discount coupon, replace that coupon with a $5 coupon. like
// Change price for discount
if( ! function_exists('custom_discount') ){
function custom_discount( $price, $values, $instance ) {
//$price represents the current product price without discount
//$values represents the product object
//$instance represent the cart object
//Get subtotal
$subtotal = WC()->cart->get_subtotal();
$coupon = WC()->cart->get_discount_total();
//if price < 50 and we have active coupon then we need decrease price to $5
if( $subtotal < 50 && ! empty( WC()->cart->get_applied_coupons() ) ){
$price = $subtotal - 5; //Wrong way ...
}
return $price;
}
add_filter( 'woocommerce_get_discounted_price', 'custom_discount', 10, 3);
}