Last active
August 29, 2015 14:22
-
-
Save JoelEadeDesign/2f5093400ff5411ca75f to your computer and use it in GitHub Desktop.
WooCommerce Exclude Free Shipping For Specific User Roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Free shipping for non-stockists | |
* Adapted from Sean Barton's snippet | |
* http://www.sean-barton.co.uk/2014/04/wordpress-snippet-woocommerce-free-shipping-role/#.VW_FaVyqpBc | |
* Click "Clear transients" (WooCommerce > System Status > Tools) if it's not working. | |
*/ | |
add_filter( 'woocommerce_package_rates', 'my_woocommerce_set_free_shipping_for_certain_users', 10, 1); | |
function my_woocommerce_set_free_shipping_for_certain_users( $rates, $package ) { | |
get_currentuserinfo(); | |
global $current_user; | |
if ($current_user->ID) { | |
$user_roles = $current_user->roles; | |
$user_role = array_shift($user_roles); | |
if ($user_role == 'stockist') { | |
unset($rates['free_shipping']); | |
} else { | |
$freeshipping = $rates['free_shipping']; | |
$rates = array(); | |
$rates[] = $freeshipping; | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment