Buy X Get Y pick the cheapest or highest product based on the product regular price
Implement "Buy X Get Y" promotions to select the cheapest or highest-priced product based on regular prices.
// Buy X Get Y pick the cheapest/highest product based on the product regular price
add_filter('advanced_woo_discount_rules_get_price_of_cart_item_on_find_cheapest_item', function($price, $product) {
if (!empty($product) && method_exists($product, 'get_regular_price')) {
return $product->get_regular_price();
}
return $price;
}, 100, 2);