I have a piece of code that adds a small fee to the checkout for a certain user role (b2bcustomer). Everything works OK.
Now I would like one particular user ID in this user role (b2bcustomer) not to be charged a fee.
I tried to complete the code below, but the fee for this user ID is still charged. Any advice?
Code in functions.php:
add_action( 'woocommerce_cart_calculate_fees', 'b2b_fee_for_gateway' );
function b2b_fee_for_gateway() {
$user_id = get_current_user_id(); /*added*/
if(is_checkout() && WC()->customer->get_role() != current_user_can( 'b2bcustomer' ) && ($user_id != 1083)) /*added && ($user_id != 1083)*/
return;
global $woocommerce;
$chosen_gateway = $woocommerce->session->chosen_payment_method;
if ( $chosen_gateway != 'cod' && current_user_can( 'b2bcustomer' ) && ($user_ID != 1083))
$surcharge = 10;
$woocommerce->cart->add_fee( 'B2B processing cost', $surcharge, true, '');
}
}
Some comments/suggestions regarding your code attempt/question
global $woocommerce;
is not necessary, since$cart
is passed to the callback functionSo you get: