function sv_discount_price_percentage($cart) { global $woocommerce; //Set the price for user role. $discount_percentage = 0.1; //כל 0.1 שווה ל10 אחוז $set_role = array('administrator', 'vendor'); //Get the login user role $user = wp_get_current_user(); $percentage_fee = ($cart->cart_contents_total + $cart->shipping_total) * $discount_percentage; $user_role = $user->roles; //Check the specifc user role for discount. if (in_array($user_role[0], $set_role)) { $cart->add_fee('הנחה באחוזים', -$percentage_fee, true); } } add_action('woocommerce_cart_calculate_fees', 'sv_discount_price_percentage');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter