Is there a way to control the order of appearance of shipping methods in Craft Commerce?

Craft CMS Asked by Panos Spiliotis on December 13, 2020

If there are multiple shipping methods available for an order, is there way to control the order in which they appear?

The CP doesn’t seem to offer a way to re-order them. I’m using something like the following code to retrieve all available methods.

{% for handle, method in cart.availableShippingMethods %}
<input type="radio" id="{{ handle }}" name="shippingMethodHandle" value="{{ handle }}" />
<label for="{{ handle }}">{{ }}</label><br>
{% endfor %}

Craft Pro ( & Craft Commerce Pro (3.1.12)

One Answer

I don't think there is any in-built way to do this, no.

A relatively easy hack to achieve it, though, is to loop through your shipping methods (as youare) - but rather than directly outputting them, instead add the data to a twig array (possibly adding some extra data long the way, such as a sortOrder of your choosing, based on the handle) - and then use Twig's sort to sort your options based on your desired criteria (e.g. the aformentioned sortOrder or just by e.g. the price - before then actually outputting those options from the array, rather than the initial direct loop.

It's not awesome/elegant, but it works!

Answered by Jeremy Daalder on December 13, 2020

Add your own answers!

Related Questions

Create matrix block with no fields

3  Asked on December 4, 2020 by joe-b


Simple way to create a slideshow with Twig and a for loop?

1  Asked on December 3, 2020 by miss-sunshine


Address validation error on add to cart

0  Asked on November 30, 2020 by sirjay


Get entries that aren’t related to current user

1  Asked on November 29, 2020 by less-and-more-collective


Feed me plugin, cURL error 60

1  Asked on November 29, 2020 by mosswalker


Setting valueless boolean attributes with the tag function

1  Asked on November 28, 2020 by jonathan-schofield


Instructions for external or integrating auth?

0  Asked on November 27, 2020 by darryl-hein


License alerts in sandbox site

1  Asked on November 27, 2020 by juanlopez4691


Is it possible exclude an entry type from result of craft.entries?

3  Asked on November 4, 2020 by hamishtaplin


Migrating categories from Entry to Asset

1  Asked on October 29, 2020 by evvvvritt


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP