Last active
May 21, 2020 02:33
-
-
Save AshlinRejo/15c0a87925f5cca08b4258fc2083bc50 to your computer and use it in GitHub Desktop.
Woo Discount Rules: For applying discount only for main product while using Woocommerce product addon
This file contains hidden or 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
if(!function_exists('woo_discount_rules_has_price_override_method')){ | |
function woo_discount_rules_has_price_override_method($has_price_override, $product, $on_apply_discount){ | |
if($on_apply_discount == 'on_apply_discount') $has_price_override = true; | |
return $has_price_override; | |
} | |
} | |
add_filter('woo_discount_rules_has_price_override', 'woo_discount_rules_has_price_override_method', 10, 3); | |
function woo_discount_rules_price_rule_final_amount_applied_method($discountedPrice, $price, $discount, $additionalDetails, $product, $product_page){ | |
if($discountedPrice < 0) $discountedPrice = 0; | |
$total_price = $product->get_price(); | |
$addon_price = 0; | |
if($price != $total_price){ | |
$addon_price = $total_price - $price; | |
} | |
$discountedPrice = $discountedPrice + $addon_price; | |
return $discountedPrice; | |
} | |
add_filter('woo_discount_rules_price_rule_final_amount_applied', 'woo_discount_rules_price_rule_final_amount_applied_method', 10, 6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment