phpwordpresswoocommercecoupon

WooCommerce custom coupon discount


I am trying to change the default WooCommerce coupon discount to a function where it adds the discount price to the total cart price. So instead of subtracting the discount it should add it up to the price.

I found that this is done in the includes/class-wc-cart.php file, in a function called:
get_discounted_price and woocommerce_get_discounted_price

I tried to add a filter to accomplish the above but it is not working quite well:

function custom_discount($price) {
     global $woocommerce;
     $undiscounted_price = $price;
     $product = $values['data'];
     $discount_amount = $coupon->get_discount_amount( 'yes' === get_option( 'woocommerce_calc_discounts_sequentially', 'no' ) ? $price : $undiscounted_price, $values, true );
     $discount_amount = min( $price, $discount_amount );
$price  = max( $price + $discount_amount, 0 );
  return $price;
}
add_filter( 'woocommerce_get_discounted_price', 'custom_discount', 10);

Anyone who can help me out on this?

Thanks


Solution

  • Ok, a thing that works is to set a negative coupon discount, like -10:)