Last active
April 20, 2020 11:12
-
-
Save strangerstudios/03cad36119165950097f to your computer and use it in GitHub Desktop.
Give members of specific level IDs Free Shipping in your WooCommerce store.
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
/* | |
* Give members of level 1 or 2 Free Shipping when free shipping is available (must set free shipping as an option in store settings). | |
* Change $pmprowc_free_shipping_levels = array(1,2); to include level IDs that receive free shipping | |
*/ | |
function my_pmprowc_free_shipping( $rates, $package ) { | |
$pmprowc_free_shipping_levels = array('1','2'); | |
if(function_exists('pmpro_hasMembershipLevel') && isset( $rates['free_shipping'] ) && pmpro_hasMembershipLevel($pmprowc_free_shipping_levels) ) | |
{ | |
// Get Free Shipping array into a new array | |
$freeshipping = array(); | |
$freeshipping = $rates['free_shipping']; | |
// Empty the $available_methods array | |
unset( $rates ); | |
// Add Free Shipping back into $avaialble_methods | |
$rates = array(); | |
$rates[] = $freeshipping; | |
} | |
else | |
{ | |
// remove free shipping option | |
unset( $rates['free_shipping'] ); | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'my_pmprowc_free_shipping' , 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment