Support » Plugin: WooCommerce Advanced Free Shipping » Hide other shipping methods EXCEPT

  • Resolved johnny538

    (@johnny538)


    I want to use the plugin and I like the ‘Hide other shipping methods when free shipping is available’. But I also have a physical store where customers can pick up their order which is free.

    Therefore I’d like to hide all ‘paid’ shipping methods, but still leave the option to pick up.

    Is this possible ? Or is it a feature you’d be willing to add ? I can imagine I’m not the only one here offering ‘pick up in store’.

    I tried adding 2 shipping rates in the plugin in hopes it would show both but it didn’t.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    I’ve made this code snippet some time ago that will also show local pickup:
    https://gist.github.com/JeroenSormani/354a5ea652ddb8a4c51d

    Hope that helps 🙂

    Cheers,
    Jeroen

    How do I apply it?

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    I’ve written this post about adding code snippets to your site: https://shopplugins.com/how-to-add-a-code-snippet-to-your-site/

    Cheers,
    Jeroen

    Hi Jeroen,

    I am sorry but I have tried to implement this exception, however after adding the snippet to the function.php as required the exception just doesn’t work?

    Please confirm I need to have the hide other shipping option set (ticked) / pasted the snipet as is in my function php, however, it will not show the Local pickup when the free shipping condition is met, just the free shipping 🙁

    In looking at the code of the page, the Local Pickup option seems to have a different name?, see below:

    <input name=”shipping_method[0]” data-index=”0″ id=”shipping_method_0_local_pickup10″ value=”local_pickup:10″ class=”shipping_method” type=”radio”>

    and the free shipping option is:

    <input name=”shipping_method[0]” data-index=”0″ id=”shipping_method_0_advanced_free_shipping” value=”advanced_free_shipping” class=”shipping_method” type=”radio”>

    Anything I am doing wrong??

    Thanks for your time

    I also found another snipet from CodeCanyon (your post of course) 🙂 as below, without success:

    function custom_hide_all_shipping_when_free_is_available( $available_methods ) {
    $to_test_methods = $available_methods;
    unset( $to_test_methods[‘local_pickup’] );
    $shipping_costs = wp_list_pluck( (array) $to_test_methods, ‘cost’, ‘id’ );
    if ( in_array( 0, $shipping_costs ) ) :
    foreach ( $available_methods as $key => $method ) :
    if ( 0 != $method->cost ) :
    unset( $available_methods[ $key ] );
    endif;
    endforeach;
    endif;
    return $available_methods;
    }
    add_filter( ‘woocommerce_package_rates’, ‘custom_hide_all_shipping_when_free_is_available’ );

    Maybe the sipping[id] // 10 is needed?

    thanks for your time 🙂

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi Stefan,

    Those code snippets are all a bit old, I wrote this one bout 2 weeks ago which should work nicely with both my plugins and WC Shipping Zones:
    https://gist.github.com/JeroenSormani/38af8a40b235246a75042f3a481d6b25

    Cheers,
    Jeroen

    Hi Jeroen,

    And thanks for your prompt reply, much appreciated.

    Just tried it out. However as a result it will only show the Local Pickup when it is not free shipping, and indeed will show both free shipping and local pickup when qty justify free shipping.

    Both plugin and WP are up to date and I placed the snippet as required in the function.php file.
    I tried with Hide other shipping method or not, same result 🙁

    In looking at your new code snipet, I realise it is targeting free_rates… I actually need to allow the Express Post as well as free-shipping for slow shipping. It is for medical goods and need to have the option to have it using Express post as well as Freeshiping when purchasing 3+ qty.
    Looking at your previous code I hoped I could just replace the Id / name of the local pickup to the Express post shipping option to have the exception in place?

    I really would appreciate your help on this, it is beyond my capacity at this stage 😐

    Thanks for your time
    Stephane

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi Stephane,

    If you still want to show a express shipping rate then using the option / code like this might not be right for your needs.

    You could modify the code further to fit your exact needs, but this would be outside what this plugin can do.

    Depending on your needs you may also be able to setup the appropriate shipping cost using my other plugin; http://codecanyon.net/item/woocommerce-advanced-shipping/8634573
    But that really depends if you use flat rates / live quotes for example.

    Hope that makes sense 🙂

    Cheers,
    Jeroen

    Hiya 🙂 I managed to find a solution for this.

    I used the code below and it basically hides the standard delivery option leaving the free + Express.

    Sorted 😉

    See the code below:

    add_filter( ‘woocommerce_package_rates’, ‘unset_shipping_when_free_is_available_in_zone’, 10, 2 );

    function unset_shipping_when_free_is_available_in_zone( $rates, $package ) {

    // Only unset rates if free_shipping is available
    if ( isset( $rates[‘advanced_free_shipping’] ) ) {
    unset( $rates[‘flat_rate:1’] );
    }

    return $rates;

    }

    }

    *************************************************
    Thanks again for your time with this.

    Plugin Author Jeroen Sormani

    (@sormano)

    Glad to hear you found a solution 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.