Last active
August 29, 2015 14:19
-
-
Save zstepek/1b72178e9cd59370d7e2 to your computer and use it in GitHub Desktop.
Conditionally add free shipping to users based on their user role.
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 | |
// Add free shipping for users in subscriber or administrator roles. | |
function mindsize_wc_conditional_free_shipping( $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 == 'subscriber' || $user_role == 'administrator') { | |
$freeshipping = $rates['free_shipping']; | |
$rates = array(); | |
$rates[] = $freeshipping; | |
} else { | |
unset($rates['free_shipping']); | |
} | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'mindsize_wc_conditional_free_shipping', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment