<p>Turns out there was nothing wrong with that code at all. In fact i had accidentally set the subscriptions with hyphens as demonstrated above, however users were set with camelCase. Code works exactly as expected now.</p>

CC BY-SA 3.0
2016-06-01T05:51:53.010Z
2016-06-01T05:51:53.010Z
Christopher Healey
<p>I have subscriptions setup with Charge and Member Groups setup for reach subscription. The handle and name of both the subscriptions as well as the related member groups is identical. Some of them have a limit of 1 person per member-group. I have the following code that should check what member groups have how many people in them and then output what is available, but for some reason, even if i manually assign users to some of the member groups, they are still being shown as options. Please advise. Code below:</p>

<pre><code>              {% set planChoices = {
            'floating-desks' : {
                'isDesk': true,
                'label': 'Floating Desk',
                'planAmount' : 175,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'floating-desks'
                    },
                }    
            },
            'private-office-220' : {
                'isDesk': false,
                'label': 'Private Office 220',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-220'
                    },
                }    
            },
            'private-office-221' : {
                'isDesk': false,
                'label': 'Private Office 221',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-221'
                    },
                }    
            },
            'private-office-230' : {
                'isDesk': false,
                'label': 'Private Office 230',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-230'
                    },
                }    
            },
            'private-office-231' : {
                'isDesk': false,
                'label': 'Private Office 231',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-231'
                    },
                }    
            },
            'private-office-232' : {
                'isDesk': false,
                'label': 'Private Office 232',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-232'
                    },
                }    
            },
            'private-office-233' : {
                'isDesk': false,
                'label': 'Private Office 233',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-233'
                    },
                }    
            },
            'private-office-234' : {
                'isDesk': false,
                'label': 'Private Office 234',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-234'
                    },
                }    
            },
            'permanent-desk-1' : {
                'isDesk': false,
                'label': 'Permanent Desk 1',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-1'
                    },
                }    
            },
            'permanent-desk-2' : {
                'isDesk': false,
                'label': 'Permanent Desk 2',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-2'
                    },
                }    
            },
            'permanent-desk-3' : {
                'isDesk': false,
                'label': 'Permanent Desk 3',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-3'
                    },
                }    
            },
            'permanent-desk-4' : {
                'isDesk': false,
                'label': 'Permanent Desk 4',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-4'
                    },
                }    
            },
            'permanent-desk-5' : {
                'isDesk': false,
                'label': 'Permanent Desk 5',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-5'
                    },
                }    
            },
            'permanent-desk-6' : {
                'isDesk': false,
                'label': 'Permanent Desk 6',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-6'
                    },
                }    
            },
            'permanent-desk-7' : {
                'isDesk': false,
                'label': 'Permanent Desk 7',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-7'
                    },
                }    
            },
            'permanent-desk-8' : {
                'isDesk': false,
                'label': 'Permanent Desk 8',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-8'
                    },
                }    
            },
            'permanent-desk-9' : {
                'isDesk': false,
                'label': 'Permanent Desk 9',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-9'
                    },
                }    
            },
            'permanent-desk-10' : {
                'isDesk': false,
                'label': 'Permanent Desk 10',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-10'
                    },
                }    
            },
            'permanent-desk-11' : {
                'isDesk': false,
                'label': 'Permanent Desk 11',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-11'
                    },
                }    
            },
            'permanent-desk-12' : {
                'isDesk': false,
                'label': 'Permanent Desk 12',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-12'
                    },
                }    
            },
            'permanent-desk-13' : {
                'isDesk': false,
                'label': 'Permanent Desk 13',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-13'
                    },
                }    
            },
            'permanent-desk-14' : {
                'isDesk': false,
                'label': 'Permanent Desk 14',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-14'
                    },
                }    
            },
            'permanent-desk-15' : {
                'isDesk': false,
                'label': 'Permanent Desk 15',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-15'
                    },
                }    
            },
            'permanent-desk-16' : {
                'isDesk': false,
                'label': 'Permanent Desk 16',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-16'
                    },
                }    
            }
        } %}
        ​
        {% set availablePlanChoices = {} %}

        {% for key, value in planChoices %}

            {% if planChoices['isDesk'] is defined and planChoices['isDesk'] %}
                {% if craft.users.group('permanent-desk-1,permanent-desk-2,permanent-desk-3,permanent-desk-4,permanent-desk-5,permanent-desk-6,permanent-desk-7,permanent-desk-8,permanent-desk-9,permanent-desk-10,permanent-desk-11,permanent-desk-12,permanent-desk-13,permanent-desk-14,permanent-desk-15,permanent-desk-16, floating-desks').total() &lt; 16 %}
                    {% set availablePlanChoices = availablePlanChoices|merge({ (key): value }) %}
                {% endif %}
            {% else %}
                {% if craft.users.group(key).total() &lt; 1 %}
                    {% set availablePlanChoices = availablePlanChoices|merge({ (key): value }) %}
                {% endif %}
            {% endif %}

        {% endfor %}
        ​

        ​
        {% set options = {
            'planChoices' : availablePlanChoices,
            'planChoiceDefault': 'floating-desks',
        } %}
        {{ craft.charge.setPaymentOptions(options) }}


         {{ forms.selectField({
                label: 'Booking Choice',
                name: 'planChoice',
                id: 'planChoice',
                options: options.planChoices,
                value: (charge is defined ? charge.planChoice),
                errors: (charge is defined ? charge.getErrors('planChoice'))
        }) }}
</code></pre>

CC BY-SA 3.0
2016-05-31T00:24:26.807Z
I'm not following the logic... `{% if craft.users.group('... list 17 group handles...').total() < 16 %}`.  If there are less than 16 groups from the list of 17 group handles I just provided?
Brad Bell
CC BY-SA 3.0
2016-05-31T01:07:42.537Z
It's suppose to check how many users are in a particular group. 23 of them 'basically everything except Floating Desks' currently have a limit of 1 user allowed in the group at a time. Floating desks however can have up to 16 (minus any already occupied by any of the' permanent desks'. Make sense now? All are being added however... regardless of whether there are already people in the user group 'above the max of 1' or not though...
Christopher Healey
<templating><users><conditional><plugin-charge>
Conditional being ignored?
# Conditional being ignored?

(Asked by: username_0 on 2016-05-30)

I have subscriptions setup with Charge and Member Groups setup for reach subscription. The handle and name of both the subscriptions as well as the related member groups is identical. Some of them have a limit of 1 person per member-group. I have the following code that should check what member groups have how many people in them and then output what is available, but for some reason, even if i manually assign users to some of the member groups, they are still being shown as options. Please advise. Code below:
              {% set planChoices = {
            'floating-desks' : {
                'isDesk': true,
                'label': 'Floating Desk',
                'planAmount' : 175,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'floating-desks'
                    },
                }    
            },
            'private-office-220' : {
                'isDesk': false,
                'label': 'Private Office 220',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-220'
                    },
                }    
            },
            'private-office-221' : {
                'isDesk': false,
                'label': 'Private Office 221',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-221'
                    },
                }    
            },
            'private-office-230' : {
                'isDesk': false,
                'label': 'Private Office 230',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-230'
                    },
                }    
            },
            'private-office-231' : {
                'isDesk': false,
                'label': 'Private Office 231',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-231'
                    },
                }    
            },
            'private-office-232' : {
                'isDesk': false,
                'label': 'Private Office 232',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-232'
                    },
                }    
            },
            'private-office-233' : {
                'isDesk': false,
                'label': 'Private Office 233',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-233'
                    },
                }    
            },
            'private-office-234' : {
                'isDesk': false,
                'label': 'Private Office 234',
                'planAmount' : 1000,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'private-office-234'
                    },
                }    
            },
            'permanent-desk-1' : {
                'isDesk': false,
                'label': 'Permanent Desk 1',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-1'
                    },
                }    
            },
            'permanent-desk-2' : {
                'isDesk': false,
                'label': 'Permanent Desk 2',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-2'
                    },
                }    
            },
            'permanent-desk-3' : {
                'isDesk': false,
                'label': 'Permanent Desk 3',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-3'
                    },
                }    
            },
            'permanent-desk-4' : {
                'isDesk': false,
                'label': 'Permanent Desk 4',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-4'
                    },
                }    
            },
            'permanent-desk-5' : {
                'isDesk': false,
                'label': 'Permanent Desk 5',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-5'
                    },
                }    
            },
            'permanent-desk-6' : {
                'isDesk': false,
                'label': 'Permanent Desk 6',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-6'
                    },
                }    
            },
            'permanent-desk-7' : {
                'isDesk': false,
                'label': 'Permanent Desk 7',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-7'
                    },
                }    
            },
            'permanent-desk-8' : {
                'isDesk': false,
                'label': 'Permanent Desk 8',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-8'
                    },
                }    
            },
            'permanent-desk-9' : {
                'isDesk': false,
                'label': 'Permanent Desk 9',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-9'
                    },
                }    
            },
            'permanent-desk-10' : {
                'isDesk': false,
                'label': 'Permanent Desk 10',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-10'
                    },
                }    
            },
            'permanent-desk-11' : {
                'isDesk': false,
                'label': 'Permanent Desk 11',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-11'
                    },
                }    
            },
            'permanent-desk-12' : {
                'isDesk': false,
                'label': 'Permanent Desk 12',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-12'
                    },
                }    
            },
            'permanent-desk-13' : {
                'isDesk': false,
                'label': 'Permanent Desk 13',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-13'
                    },
                }    
            },
            'permanent-desk-14' : {
                'isDesk': false,
                'label': 'Permanent Desk 14',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-14'
                    },
                }    
            },
            'permanent-desk-15' : {
                'isDesk': false,
                'label': 'Permanent Desk 15',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-15'
                    },
                }    
            },
            'permanent-desk-16' : {
                'isDesk': false,
                'label': 'Permanent Desk 16',
                'planAmount' : 350,
                'planInterval' : 'month',
                'planIntervalCount' : 1,
                'actions' : {
                    'onSuccess': {
                        'subscription' : 'permanent-desk-16'
                    },
                }    
            }
        } %}
        ​
        {% set availablePlanChoices = {} %}

        {% for key, value in planChoices %}

            {% if planChoices['isDesk'] is defined and planChoices['isDesk'] %}
                {% if craft.users.group('permanent-desk-1,permanent-desk-2,permanent-desk-3,permanent-desk-4,permanent-desk-5,permanent-desk-6,permanent-desk-7,permanent-desk-8,permanent-desk-9,permanent-desk-10,permanent-desk-11,permanent-desk-12,permanent-desk-13,permanent-desk-14,permanent-desk-15,permanent-desk-16, floating-desks').total() < 16 %}
                    {% set availablePlanChoices = availablePlanChoices|merge({ (key): value }) %}
                {% endif %}
            {% else %}
                {% if craft.users.group(key).total() < 1 %}
                    {% set availablePlanChoices = availablePlanChoices|merge({ (key): value }) %}
                {% endif %}
            {% endif %}

        {% endfor %}
        ​

        ​
        {% set options = {
            'planChoices' : availablePlanChoices,
            'planChoiceDefault': 'floating-desks',
        } %}
        {{ craft.charge.setPaymentOptions(options) }}


         {{ forms.selectField({
                label: 'Booking Choice',
                name: 'planChoice',
                id: 'planChoice',
                options: options.planChoices,
                value: (charge is defined ? charge.planChoice),
                errors: (charge is defined ? charge.getErrors('planChoice'))
        }) }}

**Tags:** templating, users, conditional, plugin-charge
> **Comments:**
> **username_1**: I'm not following the logic... `{% if craft.users.group('... list 17 group handles...').total() < 16 %}`.  If there are less than 16 groups from the list of 17 group handles I just provided?  
> **username_0**: It's suppose to check how many users are in a particular group. 23 of them 'basically everything except Floating Desks' currently have a limit of 1 user allowed in the group at a time. Floating desks however can have up to 16 (minus any already occupied by any of the' permanent desks'. Make sense now? All are being added however... regardless of whether there are already people in the user group 'above the max of 1' or not though...  

---

## 1 answers

### Answer by username_0 on 2016-06-01. Score: 1 | Accepted answer

Turns out there was nothing wrong with that code at all. In fact i had accidentally set the subscriptions with hyphens as demonstrated above, however users were set with camelCase. Code works exactly as expected now.


---

