Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_user_role() {
- global $current_user;
- $user_roles = $current_user->roles;
- $user_role = array_shift($user_roles);
- return $user_role;
- }
- function woocommerce_set_free_shipping_for_certain_users( $methods ) {
- global $woocommerce;
- $user_role = $this->get_user_role();
- $shippingrate = new WC_Shipping_Rate();
- $shippingrate->id = 'free_shipping';
- $shippingrate->label = 'Free Shipping';
- $shippingrate->cost = '0';
- $shippingrate->method_id = 'free_shipping';
- // Free shipping rule If user is a wholesale buyer and order is over 150 OR if user is a retail buyer and order is over 25
- if ( ( $user_role == 'wholesale_buyer' && $woocommerce->cart->subtotal_ex_tax >= 150 ) || ( $user_role != 'wholesale_buyer' && $woocommerce->cart->subtotal_ex_tax >= 25) ) {
- unset($methods);
- $methods = array();
- $methods['free_shipping'] = $shippingrate;
- }
- return $methods;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement