Last active
January 23, 2023 10:21
-
-
Save AshlinRejo/727c6f50d3338e3812736cf640aab300 to your computer and use it in GitHub Desktop.
Disocunt Rules v2: Apply sale place for non apply quantities while enabled discount apply from regular price.
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_discount_prices_of_product', function ($discount_prices, $product, $quantity, $cart_item){ | |
$regular_price = $product->get_regular_price(); | |
$sale_price = $product->get_price(); | |
$default_discount = $regular_price - $sale_price; | |
$non_applied_qty = $discount_prices['discount_lines']['non_applied']['quantity']; | |
if(($default_discount) > 0 && $non_applied_qty > 0){ | |
$discount_prices['initial_price'] = $sale_price; | |
$discount_prices['discounted_price'] = $discount_prices['discounted_price'] - (($default_discount*$non_applied_qty)/$quantity); | |
} | |
return $discount_prices; | |
}, 10, 4); | |
add_filter('advanced_woo_discount_rules_cart_strikeout_price_html', function ($new_item_price_html, $item_price, $cart_item, $cart_item_key){ | |
$regular_price = $cart_item['data']->get_regular_price(); | |
$new_item_price_html = preg_replace("/<del>(.*?)<\/del>/s", "<del>".wc_price($regular_price)."</del>", $new_item_price_html); | |
return $new_item_price_html; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment