Answers.Body: <p>Based on your comment, you're probably just missing quotes around the shipping handle:</p>
  <pre><code>{% elseif
    cart.shippingMethodHandle == 'regularFreightPrepayAndAddToPurchaseOrder' and
    (currentUser.isInGroup('distributor') or currentUser.isInGroup('distributorA')) %}
  %}
  </code></pre>
  <p>Without the quotes, Twig looks for a variable named <code>regularFreightPrepayAndAddToPurchaseOrder</code>. Since that variable doesn't exist, this results in an error.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-12T16:23:23.187Z
Answers.Text: I can't believe I made that mistake. Thanks for pointing that out. Have added quotes, but it's still not working. Have also updated post code to reflect this.
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-12T18:19:40.263Z
Answers.Text: @CreateSean Have you checked if the individual conditions are true? You can use `{% dd [some-expression] %}` to check if individual expressions / variables have the expected value. Can you also include the code for the other radio options? Maybe something is going wrong there.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-12T15:27:25.230Z
Answers.LastActivityDate: 2021-08-12T15:27:25.230Z
Answers.UserDisplayName: MoritzLost
Body: <p>I need to set the default shipping option for one specific usergroup but I cannot figure out how to do that.</p>
  <p>What I currently have that is not working is:</p>
  <pre><code>  &lt;label&gt;
      &lt;input type=&quot;radio&quot; name=&quot;shippingMethodHandle&quot; value=&quot;{{ handle }}&quot;
      {% if handle == cart.shippingMethodHandle %}
        checked
  
      {#
        // set default shipping option for distributors
        #}
      {% elseif
        cart.shippingMethodHandle == 'regularFreightPrepayAndAddToPurchaseOrder' and
        (currentUser.isInGroup('distributor') or currentUser.isInGroup('distributorA')) %}
      %}
        checked
      {% endif %}
  
      /&gt;
      &lt;strong&gt;{{ method.name }}&lt;/strong&gt;
  
      {# display price fro users not in distributers/resellers #}
      {% if not currentUser.isInGroup('distributor')
        and not currentUser.isInGroup('distributorA')
        and not currentUser.isInGroup('industrialReseller') %}
          &lt;span class=&quot;price&quot;&gt;{{ method.priceAsCurrency }}&lt;/span&gt;
      {% endif %}
      {# end conditionally dipslay price #}
    &lt;/label&gt;
  </code></pre>
  <p>Is this possible?</p>
  <hr />
  <p>Updated twig code so that the handle has qoutes around it and is not a variable. However still not working.</p>
  <p>Above code does not check or set default the expected shipping options. All options are unselected by default</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-12T13:14:51.013Z
Comments.Text: What is not working specifically? That is, what are you expecting to see and what are you actually seeing? Also, are there other radio inputs with the same name (`shippingMethodHandle`)? If you only have one radio input with the same name, it will always start out checked ...
Comments.UserDisplayName: MoritzLost
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-12T15:11:02.310Z
Comments.Text: @MoritzLost yes there are multiple shipping options. I expect the Regular Freight to be selected by default but when I add the elseif in the conditional I get an error `Variable "regularFreightPrepayAndAddToPurchaseOrder" does not exist.` but that shipping handle does exist.
Comments.UserDisplayName: CreateSean
Tags: <plugin-craftcommerce><shipping>
Title: Set Default Shipping Option for specific User Group
ThreadText: # Set Default Shipping Option for specific User Group
  
  (Asked by: username_0 on 2021-08-12)
  
  I need to set the default shipping option for one specific usergroup but I cannot figure out how to do that.
  
  What I currently have that is not working is:
  
  ```
    <label>
      <input type="radio" name="shippingMethodHandle" value="{{ handle }}"
      {% if handle == cart.shippingMethodHandle %}
        checked
  
      {#
        // set default shipping option for distributors
        #}
      {% elseif
        cart.shippingMethodHandle == 'regularFreightPrepayAndAddToPurchaseOrder' and
        (currentUser.isInGroup('distributor') or currentUser.isInGroup('distributorA')) %}
      %}
        checked
      {% endif %}
  
      />
      <strong>{{ method.name }}</strong>
  
      {# display price fro users not in distributers/resellers #}
      {% if not currentUser.isInGroup('distributor')
        and not currentUser.isInGroup('distributorA')
        and not currentUser.isInGroup('industrialReseller') %}
          <span class="price">{{ method.priceAsCurrency }}</span>
      {% endif %}
      {# end conditionally dipslay price #}
    </label>
  
  ```
  
  Is this possible?
  
  ---
  
  Updated twig code so that the handle has qoutes around it and is not a variable. However still not working.
  
  Above code does not check or set default the expected shipping options. All options are unselected by default
  
  **Tags:** plugin-craftcommerce, shipping
  
  > **Comments:**
  > **username_1**: What is not working specifically? That is, what are you expecting to see and what are you actually seeing? Also, are there other radio inputs with the same name (`shippingMethodHandle`)? If you only have one radio input with the same name, it will always start out checked ...  
  > **username_0**: @username_1 yes there are multiple shipping options. I expect the Regular Freight to be selected by default but when I add the elseif in the conditional I get an error `Variable "regularFreightPrepayAndAddToPurchaseOrder" does not exist.` but that shipping handle does exist.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-08-12. Score: 1
  
  Based on your comment, you're probably just missing quotes around the shipping handle:
  
  ```
  {% elseif
    cart.shippingMethodHandle == 'regularFreightPrepayAndAddToPurchaseOrder' and
    (currentUser.isInGroup('distributor') or currentUser.isInGroup('distributorA')) %}
  %}
  
  ```
  
  Without the quotes, Twig looks for a variable named `regularFreightPrepayAndAddToPurchaseOrder`. Since that variable doesn't exist, this results in an error.
  
  > **Comments:**
  > **username_0**: I can't believe I made that mistake. Thanks for pointing that out. Have added quotes, but it's still not working. Have also updated post code to reflect this.  
  > **username_1**: @username_0 Have you checked if the individual conditions are true? You can use `{% dd [some-expression] %}` to check if individual expressions / variables have the expected value. Can you also include the code for the other radio options? Maybe something is going wrong there.  
  
  ---
  
  