I have multiple discount tiers on my site, based on user role. After much digging and scratching and a little help from a friend I found some code that applies this discount perfectly on the cart page. Is there a way to also display this on the product page?
We used the code found here - Apply a discount for a specific user role in Woocommerce Thanks to LoicTheAztec. This is what we are currently using:
// Reseller Discounts add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_user_role', 20, 1 ); function discount_based_on_user_role( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Exit
// Discount for Reseller_45
if ( ! current_user_can('wcwp_reseller_45') )
return; // Exit
$percentage = 45;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return; // Exit
// Discount for Reseller_40
if ( ! current_user_can('wcwp_reseller_40') )
return; // Exit
$percentage = 40;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
// Discount for Reseller_35
if ( ! current_user_can('wcwp_reseller_35') )
return; // Exit
$percentage = 35;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
// Discount for Reseller_30
if ( ! current_user_can('wcwp_reseller_30') )
return; // Exit
$percentage = 30;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
// Discount for Reseller_25
if ( ! current_user_can('wcwp_reseller_25') )
return; // Exit
$percentage = 25;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
// Discount for Reseller_20
if ( ! current_user_can('wcwp_reseller_20') )
return; // Exit
$percentage = 20;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
// Discount for Reseller_15
if ( ! current_user_can('wcwp_reseller_15') )
return; // Exit
$percentage = 15;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
// Discount for Reseller_10
if ( ! current_user_can('wcwp_reseller_10') )
return; // Exit
$percentage = 10;
$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
$cart->add_fee( sprintf( __("Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
}