Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Last active October 6, 2017 18:37
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save danielbitzer/3eaef64c6651b634c3e242a6a20651bc to your computer and use it in GitHub Desktop.
How to Create a Robust WooCommerce Wholesale System
<?php
// ADD USER ROLE – YOU CAN REMOVE CODE AFTER 1ST RUN
add_role( 'wholesale', 'Wholesale Customer', array(
'read' => true
));
<?php
//  REMOVE COUPONS AND TAX FROM WHOLESALE USERS
function my_filter_woocommerce_coupons_enabled( $enabled ) {
$current_user = wp_get_current_user();
$wholesale_user_role = $current_user->has_cap( 'wholesale' );
$wholesale_vip_user_role = $current_user->has_cap( 'wholesale_vip' );
if ( $wholesale_user_role || $wholesale_vip_user_role ) {
$enabled = false;
}
return $enabled;
}
function my_filter_woocommerce_calc_tax( $taxes, $price, $rates, $price_includes_tax, $suppress_rounding ) {
$current_user = wp_get_current_user();
$wholesale_user_role = $current_user->has_cap( 'wholesale' );
$wholesale_vip_user_role = $current_user->has_cap( 'wholesale_vip' );
if ( $wholesale_user_role || $wholesale_vip_user_role ) {
$taxes = array( 1 => "float(0.000)" );
}
return $taxes;
};
add_filter( 'woocommerce_coupons_enabled' , 'my_filter_woocommerce_coupons_enabled' );
add_filter( 'woocommerce_calc_tax', 'my_filter_woocommerce_calc_tax', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment