TransWikia.com

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

Craft Pro (3.4.28.1) & 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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP