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 }}">{{ method.name }}</label><br>
{% endfor %}

Craft Pro ( & Craft Commerce Pro (3.1.12)


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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.