Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    The snippet unsets each method programmatically.

    unset( $rates['flat_rate'] );

    just don’t unset local pickup.

    Thread Starter silenx

    (@silenx)

    I use the code from https://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/

    so i have to paste this snippet?

    /**
     * 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['local_pickup'] );
    
    	}
    
    	return $rates;
    }

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    You don’t want this line:

    unset( $rates['local_pickup'] );

    That removes it!

    Thread Starter silenx

    (@silenx)

    Ok thank you, i resolved 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'] ) ) {
     unset( $rates['local_delivery'] );
    	}
    
    	return $rates;
    }

    Thread Starter silenx

    (@silenx)

    Resolved

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide national/international shipping on free shepping, but keep local pickup’ is closed to new replies.