Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1.   if( in_array( 'practitioner', (array) $user->roles) ):
  2.     $tradeDiscountTotal = 0;
  3.     $loggedInUser = get_current_user_id();
  4.  
  5.     //Get discount from user & work out numerical value as a percentage
  6.     $discountApplied = get_field('trade_discount', 'user_'. $loggedInUser );
  7.     $discountApplied = 100 / $discountApplied;
  8.  
  9.     foreach( WC()->cart->get_cart() as $cart_item ) {
  10.       if(!get_field('trade_discount_exempt', $cart_item['product_id'])) {
  11.         $tradeDiscountTotal += $cart_item['line_total'];
  12.       }
  13.     }
  14.  
  15.     //Work out discount using user discount & update the price
  16.     $totalDiscount = $tradeDiscountTotal / $discountApplied;
  17.     WC()->cart->add_fee( __('Trade Discount', 'woocommerce'), -$totalDiscount );
  18.   endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement