Last active
November 20, 2018 15:54
-
-
Save frozonfreak/1458e5a43a87812ebeab to your computer and use it in GitHub Desktop.
WooCommerce apply coupon for regular price instead of sale price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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..?