Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Balakrishnan-flycart/ea7b8c55d24cb58e9b0320462c0dd569 to your computer and use it in GitHub Desktop.
Save Balakrishnan-flycart/ea7b8c55d24cb58e9b0320462c0dd569 to your computer and use it in GitHub Desktop.
Discount rules v2: Subscription compatible - Apply discount only for subscription price (excluding sign up fee)
if(!function_exists('calculateProductPriceForWooDiscountRules')){
function calculateProductPriceForWooDiscountRules($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if ($calculate_discount_from == 'regular_price') {
if (method_exists($product, 'get_regular_price')) {
$product_price = $product->get_regular_price();
}
} else {
if (method_exists($product, 'get_sale_price')) {
$product_price = $product->get_sale_price();
}
if(empty($product_price)){
if (method_exists($product, 'get_regular_price')) {
$product_price = $product->get_regular_price();
}
}
}
return $product_price;
}
}
add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', 'calculateProductPriceForWooDiscountRules', 10, 5);
add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', 'calculateProductPriceForWooDiscountRules', 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment