Created
February 23, 2016 08:23
-
-
Save james-allan/bd92a8d87cb5fdb75796 to your computer and use it in GitHub Desktop.
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
public static function filter_package_rates( $package_rates, $package ) { | |
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); | |
if ( 'none' != WC_Subscriptions_Cart::$recurring_cart_key ) { | |
// get all the shipping methods chosen for this recurring cart key | |
$recurring_cart_shipping_methods = array(); | |
foreach ( $chosen_methods as $index => $method ) { | |
// we need to trim the trailing _0 off the index to compare against the recurring cart key | |
if ( WC_Subscriptions_Cart::$recurring_cart_key == substr( $index, 0, -2 ) ) { | |
$recurring_cart_shipping_methods[] = $method; | |
} | |
} | |
if ( 0 < count( $recurring_cart_shipping_methods ) ) { | |
foreach ( $package_rates as $shipping_method_id => $rate ) { | |
if ( ! in_array( $shipping_method_id, $recurring_cart_shipping_methods ) ) { | |
unset( $package_rates[ $shipping_method_id ] ); | |
} | |
} | |
} | |
} | |
return $package_rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment