Answers.Body: <p>100% untested, but I think one way to go would be to use <a href="http://www.yiiframework.com/doc/api/1.1/CModel#addError-detail" rel="nofollow">addError</a> on one of the <code>Commerce_OrderModel</code>'s attributes (in the <code>defineAttributes</code> method).</p>
  
  <p>Then your template could do something like:</p>
  
  <pre><code>{% if 'myShippingMethod' not in craft.commerce.availableShippingMethods|keys %}
      {% for error in order.getErrors('theAttribute') %}
          {{ error }}&lt;br /&gt;
      {% endfor %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-11T22:23:12.233Z
Answers.Text: Huh, that's a pretty clever idea. I'll run with it and see what I can do!
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-11T22:29:01.540Z
Answers.Text: Just tried it - worked perfectly. I love when a solution for something ends up being knowledge that'll help in many other areas down the road. Thanks Brad!
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-11T22:30:57.103Z
Answers.Text: Glad to help, @taylor!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-11T22:03:41.637Z
Answers.LastActivityDate: 2016-10-11T22:03:41.637Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have multiple custom shipping methods, each with rules which determine whether or not they will be available to the user. Basic things like minimum order cost and their address which would determine if a certain shipping method is available.</p>
  
  <p>There are some scenarios where a shipping method wont be available and the reason could depend. I need to be able to tell the user what exactly caused it to be unavailable.</p>
  
  <p>So for example:</p>
  
  <pre><code>public function matchOrder(\Craft\Commerce_OrderModel $order){
  
      // If this is true, do not enable shipping method.
      if($scenario_1) { return false; }
  
      // If this is true, do not enable shipping method.
      if($scenario_2) { return false; }
  
      return true;
  
  }
  </code></pre>
  
  <p>In the event that one of those is true, the shipping method is not available to the user. On the shipping page, I can check if it is enabled or not like this:</p>
  
  <pre><code>{% if 'myShippingMethod' not in craft.commerce.availableShippingMethods|keys %}{% endif %}
  </code></pre>
  
  <p>But that only does me good in simply whether or not it's available - not for knowing why it isn't available. Is there a way I could somehow 'pass' information to the templates for the shipping methods that didn't return true? That way I could tell user "This shipping method isn't available because of <code>$scenario_1</code>" or "This shipping method isn't available due to <code>$scenario_2</code>."</p>
  
  <p>Does this make sense? Trying to think of a good way to go about this. Any thoughts about how I should go about this would be super appreciated.</p>
  
Tags: <plugin-development><plugin-craftcommerce><php><shipping>
Title: Custom Shipping Method Availability in Commerce - User Messages
ThreadText: # Custom Shipping Method Availability in Commerce - User Messages
  
  (Asked by: username_0 on 2016-10-11)
  
  I have multiple custom shipping methods, each with rules which determine whether or not they will be available to the user. Basic things like minimum order cost and their address which would determine if a certain shipping method is available.
  
  There are some scenarios where a shipping method wont be available and the reason could depend. I need to be able to tell the user what exactly caused it to be unavailable.
  
  So for example:
  
  ```
  public function matchOrder(\Craft\Commerce_OrderModel $order){
  
      // If this is true, do not enable shipping method.
      if($scenario_1) { return false; }
  
      // If this is true, do not enable shipping method.
      if($scenario_2) { return false; }
  
      return true;
  
  }
  
  ```
  
  In the event that one of those is true, the shipping method is not available to the user. On the shipping page, I can check if it is enabled or not like this:
  
  ```
  {% if 'myShippingMethod' not in craft.commerce.availableShippingMethods|keys %}{% endif %}
  
  ```
  
  But that only does me good in simply whether or not it's available - not for knowing why it isn't available. Is there a way I could somehow 'pass' information to the templates for the shipping methods that didn't return true? That way I could tell user "This shipping method isn't available because of `$scenario_1`" or "This shipping method isn't available due to `$scenario_2`."
  
  Does this make sense? Trying to think of a good way to go about this. Any thoughts about how I should go about this would be super appreciated.
  
  **Tags:** plugin-development, plugin-craftcommerce, php, shipping
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-10-11. Score: 1 | Accepted answer
  
  100% untested, but I think one way to go would be to use [addError](http://www.yiiframework.com/doc/api/1.1/CModel#addError-detail) on one of the `Commerce_OrderModel`'s attributes (in the `defineAttributes` method).
  
  Then your template could do something like:
  
  ```
  {% if 'myShippingMethod' not in craft.commerce.availableShippingMethods|keys %}
      {% for error in order.getErrors('theAttribute') %}
          {{ error }}<br />
      {% endfor %}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Huh, that's a pretty clever idea. I'll run with it and see what I can do!  
  > **username_0**: Just tried it - worked perfectly. I love when a solution for something ends up being knowledge that'll help in many other areas down the road. Thanks username_1!  
  > **username_1**: Glad to help, @username_0!  
  
  ---
  
  