Created
November 29, 2022 13:25
-
-
Save AshlinRejo/50125b2d3cf769fe52a82a4d52f3e9d2 to your computer and use it in GitHub Desktop.
Discount rule v2: Check subtotal less than condition even when cart has no item
This file contains hidden or 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_is_conditions_passed', function($result, $rule_object, $rule){ | |
$conditions = $rule_object->getConditions(); | |
$cart = null; | |
if(function_exists('WC')){ | |
$cart = WC()->cart->get_cart(); | |
} | |
if(empty($cart) && !empty($conditions) && count((array)$conditions) == 1) | |
foreach ($conditions as $condition) { | |
$type = isset($condition->type) ? $condition->type : NULL; | |
if($type == 'cart_subtotal' && ($condition->options->operator == 'less_than_or_equal' || $condition->options->operator == 'less_than')){ | |
return true; | |
} | |
} | |
return $result; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment