Code Snippet to Rearrange WooCommerce Shipping Methods in the Cart

This article will help you re-arrange different shipping methods in the cart page on your website. If you are using any of the following plugins on your WooCommerce store, this article will surely help you.

All you need to do is use this Custom Code and paste it in your Appearance >> Editor >> functions.php file.

As you can see in the code snippet, the arrangement of shipping methods are in the order:
1. UPS
3. Free Shipping
4. Local Pickup
5. Flat Rate
So the cart page should display prices in the above order. This can be verified from the screenshot below :

calculated WooCommerce shipping rates

6 thoughts on “Code Snippet to Rearrange WooCommerce Shipping Methods in the Cart

  1. admin223
    admin223 says:

    Hi. I am using the above code to sort the shipping methods used on a pet supplier e-commerce site.

    One shipping option we offer is “cage kit shipping” for larger cage orders, and this is a shipping method we have through the plugin Advanced WooCommerce Shipping.

    As you can see from this screenshot ( I have done what you have indicated, and found the value of the custom shipping option to be “315”. So I have altered the code to show as follows:

    ‘315’ => array(),
    ‘wf_shipping_ups’ => array(),
    ‘wf_shipping_usps’ => array(),
    ‘free_shipping’ => array(),
    ‘local_pickup’ => array(),
    ‘legacy_flat_rate’ => array(),

    The order now displays correctly…however if I go to select that shipping method, it does NOT stay selected and does NOT add the the cage kit shipping cost to the order.

    I know the problem is coming from this code snippet for when I comment it out, the shipping method is able to be selected and adds the shipping cost to the total amount.

    Do you have any idea what the issue might be? If you want to see the issue first hand, visit my site, add a cage kit to your order and then go to the checkout page and input a fake address and try to choose the cage kit shipping method.

    Thank you in advance for your help!

  2. Donald
    Donald says:

    I’m going to enter a ticket on this, but how does one find the name of other shipping methods used to be able to put them in order? I’m using the very popular Table Rate Shipping plugin, but it’s not clear to me how to be able to use the snippet to arrange that amongst the other shipping options.

    All of this would be unnecessary if this were just a shipping option that could be assigned to zones, as is standard.

    • Anindo
      Anindo C says:

      Hi Donald,

      To know the shipping method, kindly go to the cart page, right click on the option and then click on inspect. You will get the “value” field in developer tools which you can then put in the snippet. Regarding shipping zones compatibility, we understand your point.

      However, Shipping Zone is very help full when you configure Shipping options like Free or Flat rate shipping for different zones.
      Using Shipping zone is overkill for a complete shipping solution provided by us. As you will end up configuring the same settings under multiple zones.
      It will be great if you can let us know your business requirement we will help you find an apt solution.

    • Anindo
      Anindo C says:

      Hi Marc,

      We do have a code snippet available for this. Here it is.

      If you face any problem with that snippet, you can approach our support team so that they will be able to fix your problem. Let us know if you have any queries.

Leave a Reply