Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_hook('CartTotalAdjustment', 1, function($vars) {
- $cart_adjustments = array();
- // Number of NAT services to buy before applying discount
- $PRODUCT_THRESHOLD = 3;
- // Product ids discount is applied to
- $NAT_PRODUCT_IDS = array(232, 42, 321, 321, 321, 21);
- // Holds product ID's that are in customer basket
- $selectedProductIds = [];
- // Store product ID's in a separate array
- foreach ($vars['products'] as $product) {
- $selectedProductIds[] = $product['pid'];
- }
- // Check if the number of intersected id's exceeds threshold
- if (count(array_intersect($selectedProductIds, $NAT_PRODUCT_IDS)) >= $PRODUCT_THRESHOLD) {
- $cart_adjustments = [
- "description" => "Custom discount for buying " . $PRODUCT_THRESHOLD . " number of NAT services",
- "amount" => "-10.00",
- "taxed" => false,
- ];
- }
- return $cart_adjustments;
- });
Advertisement
Add Comment
Please, Sign In to add comment