In WooCommerce, I have products with a regular price of X and a sales price of Y. I would like to add a coupon with a code for a $45.00 discount to be taken from the regular price X.
I would like the coupon to disregard the sale price so I get X-$45 NOT Y-$45. But when the coupon is not applied price Y is used.
I found the following which works for percentage discounts, but I can't seem to make it work for a fixed product discount price.
add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_coupon_get_discount_amount', 10, 5 );
function woocommerce_coupon_get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
if ($coupon->type == 'percent_product' || $coupon->type == 'percent') {
global $woocommerce;
$cart_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
$variable_product1= new WC_Product_Variation( $cart_item["variation_id"] );
$cart_total += $variable_product1 ->regular_price * $cart_item['quantity'];
}
$discount = round( ( $cart_total / 100 ) * $coupon->amount, $woocommerce->cart->dp );
return $discount;
}
return $discount;
}