Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshlinRejo/15c0a87925f5cca08b4258fc2083bc50 to your computer and use it in GitHub Desktop.
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
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