Last active
April 14, 2023 10:10
-
-
Save AshlinRejo/67d3de0f13ec13bf2973d75c002bb015 to your computer and use it in GitHub Desktop.
Discount rule v2: Check for any possible discount
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
if(!function_exists('isPossibleToHaveDiscountThroughWDR')) { | |
function isPossibleToHaveDiscountThroughWDR() { | |
$status = false; | |
if (class_exists('\Wdr\App\Controllers\DiscountCalculator')) { | |
$rules = \Wdr\App\Controllers\DiscountCalculator::$rules; | |
$cart = \Wdr\App\Helpers\Woocommerce::getCart(); | |
foreach ($rules as $rule) { | |
if ($rule->isEnabled()) { | |
if ($rule->hasConditions()) { | |
$conditions_passed = $rule->isCartConditionsPassed($cart); | |
if ($conditions_passed) { | |
$status = true; | |
break; | |
} | |
} else { | |
$status = true; | |
break; | |
} | |
} | |
} | |
} | |
return $status; | |
} | |
} | |
// Example for how to check possibility to have a discount or not | |
add_action('woocommerce_before_cart', function (){ | |
$has_discount = isPossibleToHaveDiscountThroughWDR(); | |
if($has_discount){ | |
echo "Has discount"; | |
} else { | |
echo "No discount available"; | |
} | |
}, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment