Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Balakrishnan-flycart/00f66e2ed6ca37a7d45580d9f7daa7b7 to your computer and use it in GitHub Desktop.
Save Balakrishnan-flycart/00f66e2ed6ca37a7d45580d9f7daa7b7 to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Exclude discount for add on price compatible for Woocommerce Custom Product Addons By Acowebs
add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) {
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
if($calculate_discount_from == "regular_price"){
$product_price = get_post_meta( $product_id, '_regular_price', true);
}else{
$product_price = get_post_meta( $product_id, '_price', true);
}
}
return $product_price;
}, 10, 5);
add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item, $calculate_discount_from){
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) {
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
if($calculate_discount_from == "regular_price"){
$product_price = get_post_meta( $product_id, '_regular_price', true);
}else{
$product_price = get_post_meta( $product_id, '_price', true);
}
}
return $product_price;
}, 10, 5);
add_filter('advanced_woo_discount_rules_discounted_price_of_cart_item', function($price, $cart_item, $cart_object, $calculated_cart_item_discount){
$product_id = isset($cart_item['product_id']) ? $cart_item['product_id'] : 0;
if (isset($cart_item['variation_id']) && !empty($cart_item['variation_id'])) {
$product_id = $cart_item['variation_id'];
}
if (empty($product_id)) {
return $price;
}
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) {
if($calculate_discount_from == "regular_price"){
$product_price = get_post_meta( $product_id, '_regular_price', true);
}else{
$product_price = get_post_meta( $product_id, '_price', true);
}
}
$wcpa_price = (isset($cart_item['wcpa_price']) && !empty($cart_item['wcpa_price'])) ? $cart_item['wcpa_price'] : 0 ;
if(!empty($wcpa_price)){
$add_on_price = $wcpa_price - $product_price;
$price = $price + $add_on_price;
}
return $price;
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment