Free Shipping for a Customer Role
Makes your Free Shipping method available to customers with a chosen role, such as wholesale buyers or VIPs, whatever their cart total.
Opens WPIDE on
Code
$wpide_free_ship_roles = array( 'wholesale_customer', 'vip' ); // Roles that always get free shipping.
add_filter( 'woocommerce_shipping_free_shipping_is_available', function ( $available ) use ( $wpide_free_ship_roles ) {
if ( $available || ! is_user_logged_in() ) {
return $available;
}
return (bool) array_intersect( $wpide_free_ship_roles, (array) wp_get_current_user()->roles );
}, 20 );
Notes
Add a Free Shipping method to each shipping zone first; this snippet only switches it on for the listed roles.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.