• How do I get free shipping to override paid shipping?
    Once the customer is eligible for free shipping I want this option to automatically be selected for their shipping method. Currently paid shipping is constantly selected and if customers don’t change it they are then paying for shipping and then asking me to refund. What a pain!

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter deagonbm

    (@deagonbm)

    I found this code in another forum but it doesn’t work. I added it to my functions.php and it placed the code in the header of my website publicly. Am I putting it in the wrong section?

    // Hide ALL shipping options when free shipping is available
    add_filter( ‘woocommerce_available_shipping_methods’, ‘hide_all_shipping_when_free_is_available’ , 10, 1 );

    /**
    * Hide ALL Shipping option when free shipping is available
    *
    * @param array $available_methods
    */
    function hide_all_shipping_when_free_is_available( $available_methods ) {

    if( isset( $available_methods[‘free_shipping’] ) ) :

    // Get Free Shipping array into a new array
    $freeshipping = array();
    $freeshipping = $available_methods[‘free_shipping’];

    // Empty the $available_methods array
    unset( $available_methods );

    // Add Free Shipping back into $avaialble_methods
    $available_methods = array();
    $available_methods[‘free_shipping’] = $freeshipping;
    endif;

    return $available_methods;

    Thread Starter deagonbm

    (@deagonbm)

    Ok so I just found this code which works perfectly! HOWEVER it also overrides my pickup in store option. How do I make it exclude this option?

    Thanks

    <?php
    /**
    * Hide shipping rates when free shipping is available.
    * Updated to support WooCommerce 2.6 Shipping Zones.
    *
    * @param array $rates Array of rates found for the package.
    * @return array
    */
    function my_hide_shipping_when_free_is_available( $rates ) {
    $free = array();
    foreach ( $rates as $rate_id => $rate ) {
    if ( ‘free_shipping’ === $rate->method_id ) {
    $free[ $rate_id ] = $rate;
    break;
    }
    }
    return ! empty( $free ) ? $free : $rates;
    }
    add_filter( ‘woocommerce_package_rates’, ‘my_hide_shipping_when_free_is_available’, 100 );

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Free Shipping help’ is closed to new replies.