-
-
Save Balakrishnan-flycart/1997b5dc804681973b84bcd296a488e4 to your computer and use it in GitHub Desktop.
Discount rules v2: Subscription compatible - Remove subscription price discount for Recurring totals(excluding sign up fee)
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('advanced_woo_discount_rules_discounted_price_of_cart_item', function ($price, $cart_item, $cart_object, $calculated_cart_item_discount){ | |
if ( !empty( $cart_object->recurring_cart_key ) ) { | |
$product = isset($cart_item['data']) ? $cart_item['data'] : array(); | |
if(!empty($product)){ | |
if (method_exists($product, 'get_sale_price')) { | |
$price = $product->get_sale_price(); | |
} | |
if(empty($price)){ | |
if (method_exists($product, 'get_regular_price')) { | |
$price = $product->get_regular_price(); | |
} | |
} | |
} | |
} | |
return $price; | |
}, 10 , 4); | |
add_filter('woocommerce_cart_item_product', function ($cart_item_data, $cart_item, $cart_item_key){ | |
$cart_key = isset($cart_item['key'])? $cart_item['key'] : ''; | |
if(!empty($cart_key) && class_exists('\Wdr\App\Controllers\ManageDiscount')){ | |
$discounted_price = isset(\Wdr\App\Controllers\ManageDiscount::$calculated_cart_item_discount[$cart_key]['discounted_price_with_tax']) ? \Wdr\App\Controllers\ManageDiscount::$calculated_cart_item_discount[$cart_key]['discounted_price_with_tax'] : 0 ; | |
if(!empty($discounted_price)){ | |
if (method_exists($cart_item_data, 'set_price')) { | |
$cart_item_data->set_price($discounted_price); | |
} | |
} | |
} | |
return $cart_item_data; | |
}, 9, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment