Code Snippet to rearrange shipping methods in cart page

The code snippet facilitates you to rearrange shipping methods in cart page.

Add the following code to your functions.php or anywhere relevant.

You can see in the code snippet, the arrangement of shipping methods are in the order:
1. UPS
2. USPS
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 :

Cart

Cart

 

 

Comments (6)

  • admin223
    admin223

    Hi. I am using the above code to sort the shipping methods used on a pet supplier ecommerce site:

    http://hedgehogcity.com

    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 (https://i.imgur.com/CZOal1s.jpg) 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 http://hedgehogcity.com, add a cage kit to your order (https://hedgehogcity.com/shop/cages/basic-hedgehog-cage-kit/) 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!

    March 5, 2018 at 8:10 pm
    • Anindo
      Anindo

      Hi,

      Thanks for reaching out to us.

      Can you please raise a ticket via the Support Forum?
      So that we can check this issue.

      Let us know if you have any query.
      Regards,

      March 6, 2018 at 5:19 pm
  • Donald
    Donald

    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.

    February 4, 2018 at 8:15 am
    • Anindo
      Anindo

      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.

      February 5, 2018 at 2:30 pm
  • Marc
    Marc

    Hi Besty,

    I’m looking for this code to also have the ability to sort by price within each method. Lowest price first at the top.

    Can you do that?

    Thanks!

    December 2, 2017 at 11:46 am
    • Anindo
      Anindo

      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 query.

      December 4, 2017 at 3:24 pm

Leave a Reply