Skip to content

Instantly share code, notes, and snippets.

@JoelEadeDesign
Last active August 29, 2015 14:22
Show Gist options
  • Save JoelEadeDesign/2f5093400ff5411ca75f to your computer and use it in GitHub Desktop.
Save JoelEadeDesign/2f5093400ff5411ca75f to your computer and use it in GitHub Desktop.
WooCommerce Exclude Free Shipping For Specific User Roles
<?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