Skip to content

Instantly share code, notes, and snippets.

  • Save Balakrishnan-flycart/1997b5dc804681973b84bcd296a488e4 to your computer and use it in GitHub Desktop.
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)
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