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)
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
2 Asked on April 20, 2021 by stig-meln-bratvold
1 Asked on April 20, 2021 by samerivertwice
0 Asked on April 18, 2021 by brimby
1 Asked on April 15, 2021
1 Asked on April 13, 2021
1 Asked on April 12, 2021
0 Asked on April 11, 2021 by killerpixler
0 Asked on April 10, 2021 by laurence-cope
1 Asked on April 9, 2021
0 Asked on April 9, 2021
1 Asked on April 7, 2021 by mark-notton
1 Asked on April 6, 2021 by analog-junkie
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP