/** * Hide ALL shipping options when free shipping is available and customer is NOT in certain states * * 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; }

Welcome to Flatsome

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *