sunjack
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: [WooCommerce] Local pickup choice even if shipping is freeThanks!
By the way I’ve tried with this:/** * woocommerce_package_rates is a 2.1+ hook */ add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 ); /** * Hide shipping rates when free shipping is available * * @param array $rates Array of rates found for the package * @param array $package The package array/object being shipped * @return array of modified rates */ function hide_shipping_when_free_is_available( $rates, $package ) { // Only modify rates if free_shipping is present if ( isset( $rates['free_shipping'] ) ) { // To unset a single rate/method, do the following. This example unsets flat_rate shipping unset( $rates['flat_rate'] ); } return $rates; }but I still can’t see local pickup when shipping is free.
Forum: Plugins
In reply to: [WooCommerce] Local pickup choice even if shipping is freeHi Caleb,
thanks for your answer.The problem was the following code snippet I’ve added to my functions.php to disable flat rate when shipping is free:
/** * Hide ALL shipping options when free shipping is available and customer is NOT in certain states * Hide Free Shipping if customer IS in those states * * UPDATED FOR WOOCOMMERCE 2.1 * * Change $excluded_states = array( 'AK','HI','GU','PR' ); to include all the states that DO NOT have free shipping */ add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 2 ); /** * Hide ALL Shipping option when free shipping is available * * @param array $available_methods */ function hide_all_shipping_when_free_is_available( $rates, $package ) { $excluded_states = array( 'AK','HI','GU','PR' ); if( isset( $rates['free_shipping'] ) AND !in_array( WC()->customer->shipping_state, $excluded_states ) ) : // 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; endif; if( isset( $rates['free_shipping'] ) AND in_array( WC()->customer->shipping_state, $excluded_states ) ) { // remove free shipping option unset( $rates['free_shipping'] ); } return $rates; }I’d like to hide flat rate when shipping is free without causing other conflicts.
Thanks,
Alberto
Viewing 2 replies - 1 through 2 (of 2 total)