Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AshlinRejo/50125b2d3cf769fe52a82a4d52f3e9d2 to your computer and use it in GitHub Desktop.
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
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