I just noticed I had to update some templates after updating to the latest Commerce version (2.0.2).

How does one go about getting the method's rule description?

I currently have it set up to apply a rule based on geographical shipping location (like contiguous US states / Hawaii and Alaska / Russia / World / Oceania)—but {{ method.description }} from within {% for handle, method in cart.availableShippingMethods %} breaks the site.


  • I would also want to display the rule name together with description. Right now it only displays the method name. – Anders Jan 27 '19 at 22:09


{% set methods = cart.availableShippingMethods %}

which is the same as calling:

{% set methods = craft.commerce.shippingMethods.getAvailableShippingMethods(cart) %}

the above returns an array of shipping method models, keyed by the shipping method handle.

to get the matching rule for each available method

{% for method in methods %}
{% set rule = method.getMatchingShippingRule(cart) %}
{% set price = method.getPriceForOrder(cart) %}
{% endfor %}

You have to can loop through the shipping rules for the shipping method.

{% for handle, method in cart.availableShippingMethods %}

  {% if method.shippingRules|length %}
    {% for shippingRule in method.shippingRules %}
      {{ shippingRule.name }}
      {{ shippingRule.description }}
    {% endfor %}
  {% endif %}

{% endfor %}

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.