Answers.Body: <p>To get the general shipping rule when you have the shipping method:</p>
  <pre><code>{% for handle, method in cart.availableShippingMethodOptions %}
    ...
    {% set rule = method.getMatchingShippingRule(cart) %}
    {% if rule %}
      {{ rule.name }} 
    {% endif %}
    ...
  {% endfor %}
  </code></pre>
  <p>to get some property of the order conditions rules something like this would likely be it:</p>
  <pre><code>{% set condition = rule.orderCondition.conditionRules|filter(item =&gt; item is instance of ('craft\\commerce\\elements\\conditions\\orders\\ShippingAddressZoneConditionRule'))|first %}
  
  {% if condition %}
     
      Shipping zone IDs in this condition rule: {{ condition.getValues()|join(',') }} 
  {% else %}
      {# No condition of the specified class was found #}
      &lt;p&gt;No ShippingAddressZoneConditionRule found.&lt;/p&gt;
  {% endif %}
  </code></pre>
  <p>in php something like this</p>
  <pre class="lang-php prettyprint-override"><code>$rule = Plugin::getInstance()-&gt;getShippingRules()-&gt;getAllShippingRules()[0];
  $condition = collect($rule-&gt;getOrderCondition()-&gt;getConditionRules())
      -&gt;firstWhere(fn($item) =&gt; $item instanceof craft\commerce\elements\conditions\orders\ShippingAddressZoneConditionRule);
  $zoneIds = $condition-&gt;getValues();
  </code></pre>
  <p>Hope that helps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-26T07:19:16.507Z
Answers.Text: Great! Is it possible to translate the rule name and description from the CP? I run a multilingual shop.
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-23T09:20:11.007Z
Answers.LastActivityDate: 2024-08-23T09:20:11.007Z
Answers.UserDisplayName: Luke Holder
Body: <p>In Craft Commerce 5, when selecting a shipping method, I list the available options using <code>cart.availableShippingMethodOptions</code> like this:</p>
  <pre><code>{% for handle, method in cart.availableShippingMethodOptions %}
      Method: {{ method.name }}
      Price: {{ method.getPrice() | commerceCurrency(cart.currency) }}
  {% endfor %}
  </code></pre>
  <p>However, I would like to display more details about each available shipping method, including:</p>
  <ul>
  <li>Listing the corresponding Shipping Rule.</li>
  <li>Displaying the Shipping Rule description.</li>
  <li>Describing the &quot;Match Order&quot; criteria in plain text.</li>
  </ul>
  <p>In my project, for example, I have two available methods:</p>
  <ul>
  <li>Click &amp; Collect</li>
  <li>Delivery</li>
  </ul>
  <p>I would like to specify the following details, ideally defined directly from the shipping method configuration (without using Globals or hardcoding text):</p>
  <ul>
  <li><p><strong>Click &amp; Collect</strong>:</p>
  <ul>
  <li><strong>Shipping Rule Description</strong>: Collection is possible during our store's business days.</li>
  <li><strong>Match Order</strong>: Always free (Base Rate Cost = 0).</li>
  </ul>
  </li>
  <li><p><strong>Delivery</strong>:</p>
  <ul>
  <li><strong>Shipping Rule Description</strong>: Free delivery for orders over €100.</li>
  <li><strong>Match Order</strong>: Free for orders over €100 (Base Rate Cost = 7 / Match Order: Total price is less than €100).</li>
  </ul>
  </li>
  </ul>
  <p>What is the most appropriate way to retrieve and display these additional details for each shipping method?</p>
  
Tags: <plugin-craftcommerce><shippingrules>
Title: Craft Commerce 5: Displaying Additional Shipping Method Details
ThreadText: # Craft Commerce 5: Displaying Additional Shipping Method Details
  
  (Asked by: username_0 on 2024-08-23)
  
  In Craft Commerce 5, when selecting a shipping method, I list the available options using `cart.availableShippingMethodOptions` like this:
  
  ```
  {% for handle, method in cart.availableShippingMethodOptions %}
      Method: {{ method.name }}
      Price: {{ method.getPrice() | commerceCurrency(cart.currency) }}
  {% endfor %}
  
  ```
  
  However, I would like to display more details about each available shipping method, including:
  
  * Listing the corresponding Shipping Rule.
  * Displaying the Shipping Rule description.
  * Describing the "Match Order" criteria in plain text.
  
  In my project, for example, I have two available methods:
  
  * Click & Collect
  * Delivery
  
  I would like to specify the following details, ideally defined directly from the shipping method configuration (without using Globals or hardcoding text):
  
  * **Click & Collect**:
  
    + **Shipping Rule Description**: Collection is possible during our store's business days.
    + **Match Order**: Always free (Base Rate Cost = 0).
  * **Delivery**:
  
    + **Shipping Rule Description**: Free delivery for orders over €100.
    + **Match Order**: Free for orders over €100 (Base Rate Cost = 7 / Match Order: Total price is less than €100).
  
  What is the most appropriate way to retrieve and display these additional details for each shipping method?
  
  **Tags:** plugin-craftcommerce, shippingrules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-08-23. Score: 2 | Accepted answer
  
  To get the general shipping rule when you have the shipping method:
  
  ```
  {% for handle, method in cart.availableShippingMethodOptions %}
    ...
    {% set rule = method.getMatchingShippingRule(cart) %}
    {% if rule %}
      {{ rule.name }} 
    {% endif %}
    ...
  {% endfor %}
  
  ```
  
  to get some property of the order conditions rules something like this would likely be it:
  
  ```
  {% set condition = rule.orderCondition.conditionRules|filter(item => item is instance of ('craft\\commerce\\elements\\conditions\\orders\\ShippingAddressZoneConditionRule'))|first %}
  
  {% if condition %}
     
      Shipping zone IDs in this condition rule: {{ condition.getValues()|join(',') }} 
  {% else %}
      {# No condition of the specified class was found #}
      <p>No ShippingAddressZoneConditionRule found.</p>
  {% endif %}
  
  ```
  
  in php something like this
  
  ```php
  $rule = Plugin::getInstance()->getShippingRules()->getAllShippingRules()[0];
  $condition = collect($rule->getOrderCondition()->getConditionRules())
      ->firstWhere(fn($item) => $item instanceof craft\commerce\elements\conditions\orders\ShippingAddressZoneConditionRule);
  $zoneIds = $condition->getValues();
  
  ```
  
  Hope that helps.
  
  > **Comments:**
  > **username_0**: Great! Is it possible to translate the rule name and description from the CP? I run a multilingual shop.  
  
  ---
  
  