SHARE
TWEET

Untitled

a guest Aug 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top