Somebody previously asked a question similar to mine, but the solutions offered do not seem to help me.
I am working on a wholesale website. For first time buyers, the minimum order is $500. For returning buyers / reorders there is no minimum. I am assuming I need to make 2 different wholesale user roles - one for first time buyers and the other for returning / reorder buyers. I was thinking Wholesale New and Wholesale Reorder would work. How do I apply this to the functions.php? This is the code I am currently using:
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 500;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->total )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->total )
), 'error'
);
}
}
Any help would be greatly appreciated.
You need current_user_can()
to test the current user's capability to do something.
First, you would need to create a new role for users who don't have any restrictions. The Members plugin is genius for creating roles and editing their capabilities.
For example, you could create a Returning Wholesaler
role.
You should duplicate the "Customer" role's capabilities... so read
, edit_posts
, and delete_posts
.
And then, add a new capability called wholesale_reorder
Then you can convert your if statement from:
if ( WC()->cart->total < $minimum )
to:
if ( WC()->cart->total < $minimum && ! current_user_can( 'wholesale_reorder' ) )
If you don't have any existing customers, don't need multiple levels of wholesale, don't have wholesale in conjunction with regular customers, and you don't have a way to register without ordering, then ostensibly you could skip adding new roles and just test current_user_can('customer')
as the only people who would be customers would be those who have ordered something already.