Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( in_array( 'practitioner', (array) $user->roles) ):
- $tradeDiscountTotal = 0;
- $loggedInUser = get_current_user_id();
- //Get discount from user & work out numerical value as a percentage
- $discountApplied = get_field('trade_discount', 'user_'. $loggedInUser );
- $discountApplied = 100 / $discountApplied;
- foreach( WC()->cart->get_cart() as $cart_item ) {
- if(!get_field('trade_discount_exempt', $cart_item['product_id'])) {
- $tradeDiscountTotal += $cart_item['line_total'];
- }
- }
- //Work out discount using user discount & update the price
- $totalDiscount = $tradeDiscountTotal / $discountApplied;
- WC()->cart->add_fee( __('Trade Discount', 'woocommerce'), -$totalDiscount );
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement