• Is there a way to hide flate rate shipping when a certain amount has been reached and kick in FREE SHIPPING ? The code below used to work until the upgrade now it gives you both options which is not good when someone goes to purchase a product that would require a shipping fee they will just choose FREE SHIPPING every time

    add_filter( 
    
    'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
    function hide_shipping_when_free_is_available( $rates, $package ) {
    
    if ( isset( $rates['free_shipping'] ) ) {
    unset( $rates['flat_rate'] ); 
    
    $free_shipping = $rates['free_shipping'];
    $rates = array();
    $rates['free_shipping'] = $free_shipping;
    }
    return $rates;
    }
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_country']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);
    unset($fields['order']['order_comments']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_email']);
    unset($fields['billing']['billing_city']);
    return $fields;
    }

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Is there a way to hide flate rate shipping when a certain amount has been reached and kick in FREE SHIPPING ?

    Try this snippet:

    // Hide standard shipping option when free shipping is available
    add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
    
    /**
     *  Hide Standard Shipping option when free shipping is available
     *
     * @param array $available_methods
     */
    function hide_standard_shipping_when_free_is_available( $available_methods ) {
        if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {
            // remove standard shipping option
            unset( $available_methods['flat_rate'] );
        }
        return $available_methods;
    }

    now it gives you both options which is not good when someone goes to purchase a product that would require a shipping fee they will just choose FREE SHIPPING every time

    Do both flat rate and free shipping come up as options all the time, but it should only be one? The above snippet should hide flat rate when the order meets the requirements for free shipping, but if both show up when it should be flat rate then you may have something wrong in your settings for when free shipping kicks in.

    Thread Starter BARTNKCMO

    (@bartnkcmo)

    Tried the snippet you posted and still both options show up ..

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide FREE SHIPPING’ is closed to new replies.