<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>

CC BY-SA 4.0
2021-08-12T16:23:23.187Z
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.
CreateSean
CC BY-SA 4.0
2021-08-12T18:19:40.263Z
@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.
MoritzLost
CC BY-SA 4.0
2021-08-12T15:27:25.230Z
2021-08-12T15:27:25.230Z
MoritzLost
<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>

CC BY-SA 4.0
2021-08-12T13:14:51.013Z
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 ...
MoritzLost
CC BY-SA 4.0
2021-08-12T15:11:02.310Z
@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.
CreateSean
<plugin-craftcommerce><shipping>
Set Default Shipping Option for specific User Group
# 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:
  
    
    {{ method.name }}

    {# display price fro users not in distributers/resellers #}
    {% if not currentUser.isInGroup('distributor')
      and not currentUser.isInGroup('distributorA')
      and not currentUser.isInGroup('industrialReseller') %}
        {{ method.priceAsCurrency }}
    {% endif %}
    {# end conditionally dipslay price #}
  

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.  

---

