/add-role.php Secret
Last active
October 6, 2017 18:37
Star
You must be signed in to star a gist
How to Create a Robust WooCommerce Wholesale System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ADD USER ROLE – YOU CAN REMOVE CODE AFTER 1ST RUN | |
add_role( 'wholesale', 'Wholesale Customer', array( | |
'read' => true | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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