New Landing How can we help? Themeforest Theme Support Neighborhood Hiding irrelevant shipping options according to order amount

Viewing 3 posts - 1 through 3 (of 3 total)
  • #208580
    sittingprettyclothing
    Member
    Post count: 123

    Hi,

    We offer free shipping for order that reach a certain amount and flat rate for orders below that threshold.
    When we created our site, you guys gave a super little code to add to our fonction.php in our child theme that allowed to hide the flat rate shipping for the orders that qualify for free shipping, and hide the free shipping for the orders that don’t. it worked fine until the latest update but not anymore 🙁

    I am guessing it needs some updating? Could you possibly have a look at it?

    Thanks a mill!

    here is the code:

    /* custom PHP functions below this line */
    // 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;
    }

    #208583
    sittingprettyclothing
    Member
    Post count: 123

    Hi

    this is resolved. I found a new code on the woocommerce site:

    /**
    * 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[‘flat_rate’] );

    // To unset all methods except for free_shipping, do the following
    $free_shipping = $rates[‘free_shipping’];
    $rates = array();
    $rates[‘free_shipping’] = $free_shipping;
    }

    return $rates;
    }

    #209160
    David Martin – Support
    Moderator
    Post count: 20834

    Great, glad you got this resolved and thanks for the code – it will hopefully help others also.

    – David.

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

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register