Posted on

How can I prevent subscriber role from bidding?

To accomplish that you can use code snippet below:

/*
Code snippet that prevents bidding based on user role
Add to your functions.php
*/

add_filter( 'auctions_for_woocommerce_before_place_bid_filter' , 'afw_prevent_bid_by_user_role' );
function afw_prevent_bid_by_user_role() {
$current_user = wp_get_current_user();
if ( in_array ( 'subscriber', $current_user->roles ) ){
wc_add_notice( esc_html__('Your user role cannot bid.', 'auctions-for-woocommerce'), 'error' );
return FALSE;
} else {
// user can place a bid
return TRUE;
}
}