I'm using Progressive discount based on cart total in WooCommerce answer code to make some Woocommerce order total discounts (see below). But I would like to make a discount based on user role, as each of my customer roles sees different prices.
I have some custom user roles: wholesale_prices
, wholesale_vat_exc
, and distributor_prices
.
I want to make the code to work just for wholesale_prices
and wholesale_vat_exc
user roles, but not for distributor_prices
(as they must not see the discounts).
Here is my actual revisited code version:
// Order total discount
add_action( 'woocommerce_cart_calculate_fees', 'progressive_discount_based_on_cart_total', 10, 1 );
function progressive_discount_based_on_cart_total( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$cart_total = $cart_object->cart_contents_total; // Cart total
if ( $cart_total >= 3000.00 && $cart_total < 5000.00 )
$percent = 15; // 15%
elseif ( $cart_total >= 1500.00 && $cart_total < 3000.00 )
$percent = 10; // 10%
elseif ( $cart_total >= 750.00 && $cart_total < 1500.00 )
$percent = 5; // 5%
else
$percent = 0;
if ( $percent != 0 ) {
$discount = $cart_total * $percent / 100;
$cart_object->add_fee( "Bulk Order Discount ($percent%)", -$discount, true );
}
}
How to make this code only available to wholesale_prices
and wholesale_vat_exc
user roles?