Guest User

WHCMS stuff

a guest
Mar 29th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. add_hook('CartTotalAdjustment', 1, function($vars) {
  3.     $cart_adjustments = array();
  4.    
  5.     // Number of NAT services to buy before applying discount
  6.     $PRODUCT_THRESHOLD = 3;
  7.  
  8.     // Product ids discount is applied to
  9.     $NAT_PRODUCT_IDS = array(232, 42, 321, 321, 321, 21);
  10.    
  11.     // Holds product ID's that are in customer basket
  12.     $selectedProductIds = [];
  13.    
  14.     // Store product ID's in a separate array
  15.     foreach ($vars['products'] as $product) {
  16.         $selectedProductIds[] = $product['pid'];
  17.     }
  18.    
  19.     // Check if the number of intersected id's exceeds threshold
  20.     if (count(array_intersect($selectedProductIds, $NAT_PRODUCT_IDS)) >= $PRODUCT_THRESHOLD) {
  21.         $cart_adjustments = [
  22.             "description" => "Custom discount for buying " . $PRODUCT_THRESHOLD . " number of NAT services",
  23.             "amount" => "-10.00",
  24.             "taxed" => false,
  25.         ];
  26.     }
  27.     return $cart_adjustments;
  28. });
Advertisement
Add Comment
Please, Sign In to add comment