AnswerBun.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!

Related Questions

Use dropdown field to add a class to the body tag

2  Asked on April 20, 2021 by stig-meln-bratvold

   

Troubleshooting General Slowness?

0  Asked on April 15, 2021

 

Wildcard subdomain for posts

2  Asked on April 13, 2021

 

CSS and JS tags with custom version parameter

0  Asked on April 11, 2021 by killerpixler

       

Use Emoji in Title?

1  Asked on April 9, 2021

   

Free-form integration to the website

1  Asked on April 8, 2021 by bree-mansell

 

List out all “Layout Tabs” in the frontend

1  Asked on April 7, 2021 by mark-notton

 

Ask a Question

Get help from others!

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