Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
Last active November 20, 2018 15:54
Show Gist options
  • Save frozonfreak/1458e5a43a87812ebeab to your computer and use it in GitHub Desktop.
Save frozonfreak/1458e5a43a87812ebeab to your computer and use it in GitHub Desktop.
WooCommerce apply coupon for regular price instead of sale 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;
}
@ruurdv
Copy link

ruurdv commented Mar 29, 2018

Would love to see a solution that works with fixed discount amounts. Any one has an idea?

Also, using this piece of code brakes the 'add to cart'-button? It's wont redirect to the cart after clicking? The page keeps loading..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment