Advertisement
Guest User

woocommerce_set_free_shipping_for_certain_users

a guest
Dec 19th, 2013
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. function get_user_role() {
  2. global $current_user;
  3.  
  4. $user_roles = $current_user->roles;
  5. $user_role = array_shift($user_roles);
  6.  
  7. return $user_role;
  8. }
  9.  
  10. function woocommerce_set_free_shipping_for_certain_users( $methods ) {
  11. global $woocommerce;
  12. $user_role = $this->get_user_role();
  13.  
  14. $shippingrate = new WC_Shipping_Rate();
  15. $shippingrate->id = 'free_shipping';
  16. $shippingrate->label = 'Free Shipping';
  17. $shippingrate->cost = '0';
  18. $shippingrate->method_id = 'free_shipping';
  19.  
  20. // 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
  21. if ( ( $user_role == 'wholesale_buyer' && $woocommerce->cart->subtotal_ex_tax >= 150 ) || ( $user_role != 'wholesale_buyer' && $woocommerce->cart->subtotal_ex_tax >= 25) ) {
  22. unset($methods);
  23. $methods = array();
  24. $methods['free_shipping'] = $shippingrate;
  25. }
  26. return $methods;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement