Created
October 27, 2015 08:01
-
-
Save WPprodigy/75203edae00875d1fcd9 to your computer and use it in GitHub Desktop.
Conditionally toggle Free Shipping based on the user's role and contents of the cart
This file contains 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
function wc_ninja_free_shipping_for_a_user_role( $rates, $package ) { | |
// Only modify rates if free_shipping is present | |
if ( isset( $rates['free_shipping'] ) ) { | |
// Add a user role specific capability here | |
if ( ! current_user_can( 'manage_woocommerce' ) ) { | |
// Cart Subtotal | |
$subtotal = WC()->cart->subtotal; | |
// Number of products in the cart | |
$count = WC()->cart->cart_contents_count; | |
// Add some optional conditions here using $subtotal and $count | |
if ( $count >= 50 || $subtotal >= 150) { | |
unset( $rates['free_shipping'] ); | |
} | |
} | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'wc_ninja_free_shipping_for_a_user_role', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment