WooCommerce – Sort shipping options / methods / services by shipment cost


WooCommerce doesn’t sort the shipping methods / services by default while showing it on cart and checkout page.

Code Snippet for sorting the shipping options by cost.

Below code snippet will help to sort the shipping options by shipping cost.

Screenshot – Shipping Options – Default view.

WooCommerce Shipping Services

Screenshot – Shipping Options – Sorted view.

WooCommerce Shipping Services Sorted.

 

 

Comments (12)

  • Phong
    Phong

    Code still works! Thank you!

    June 25, 2018 at 10:36 pm
  • Marc
    Marc

    This used to work up until we upgraded woocommerce to 3.2.5 and wordpress to 4.9.1 now when something is added to the cart, it returns this error:

    Warning: array_keys() expects parameter 1 to be array, null given in /home4/ffxbmeus/public_html/wp-content/plugins/woocommerce/includes/wc-cart-functions.php on line 478

    Warning: array_keys() expects parameter 1 to be array, null given in /home4/ffxbmeus/public_html/wp-content/plugins/woocommerce/includes/wc-cart-functions.php on line 449

    Warning: current() expects parameter 1 to be array, null given in /home4/ffxbmeus/public_html/wp-content/plugins/woocommerce/includes/wc-cart-functions.php on line 450

    Warning: array_keys() expects parameter 1 to be array, null given in /home4/ffxbmeus/public_html/wp-content/plugins/woocommerce/includes/wc-cart-functions.php on line 478

    Warning: array_keys() expects parameter 1 to be array, null given in /home4/ffxbmeus/public_html/wp-content/plugins/woocommerce/includes/wc-cart-functions.php on line 449

    Warning: current() expects parameter 1 to be array, null given in /home4/ffxbmeus/public_html/wp-content/plugins/woocommerce/includes/wc-cart-functions.php on line 450

    December 2, 2017 at 7:39 am
    • Anindo
      Anindo

      Hi Marc,

      We tested this on our side but could not replicate the issue. Would it be possible for you to approach our support team on this so that they can resolve the problem? Here is the URL of support.

      December 4, 2017 at 3:22 pm
  • Scott
    Scott

    Works Perfectly, Thanks a lot!

    May 16, 2017 at 8:31 pm
    • Ipshita
      Ipshita

      You are welcome. 🙂
      Thanks!

      May 16, 2017 at 11:04 pm
  • Rahim
    Rahim

    thats for the code, it works great!

    May 12, 2017 at 2:28 pm
    • Ipshita
      Ipshita

      You are welcome. 🙂
      Thanks!

      May 12, 2017 at 5:02 pm
  • clymer.jim
    clymer.jim

    Where is the code snippet?

    October 22, 2016 at 12:08 am
    • Vj
      Vj

      You will find it under the title “Code Snippet for sorting the shipping options by cost.”.

      October 22, 2016 at 12:18 am
    • clymer.jim
      clymer.jim

      One should be careful with this code snippet. It sorts the shipping correctly, however, it causes an error to appear that says “no shipping method has been selected” when clicking the payment button. I’m using the latest version of wordpress (4.6.1) and woocommerce (2.6.6).

      October 22, 2016 at 7:07 am
    • clymer.jim
      clymer.jim

      Strange. I can’t see the code snippet. I tried 3 different browsers. I see the title and the screenshots, but no code snippet.

      October 22, 2016 at 12:26 am
  • Gayathri

    Worked! Thank you for this snippet

    August 30, 2016 at 8:27 pm

Leave a Reply