XF 1.5 Hide user upgrades

Andy.N

Well-known member
I have 2 main user upgrades A, B and 2 sub user upgrades subA, subB. I would like to hide subA, subB using template conditionals or CSS if possible.

I only want to show subA for people who have purchased A and the regular members do not see it. Similar to B and subB.

Thank you.
 
I haven't tried this out, but it should in theory work. You will need to adjust subA, subB, A and B to your values.
Wrap the content of <xen:foreach loop="$available" value="$upgrade"> with
HTML:
<xen:if is="$upgrade.user_upgrade_id == subA AND !{xen:helper ismemberof, $visitor, A}">
    //do nothing in this case
<xen:elseif is="$upgrade.user_upgrade_id == subB AND !{xen:helper ismemberof, $visitor, B}" />
    //do nothing aswell
<xen:else />
    //here comes the actual content of the foreach loop
</xen:if>
 
Love all the help you provide @yoloswaggerino
I think this may actually work. I'm trying to see how this goes. Here is the content of the original account upgrade template. If you have further thoughts, let me know. I do appreciate the time.

Code:
<xen:title>{xen:phrase account_upgrades}</xen:title>

<xen:require css="account_upgrades.css" />

<xen:if is="{$available}">
    <div class="section">
        <h3 class="subHeading">{xen:phrase available_upgrades}</h3>
        <ul>
        <xen:foreach loop="$available" value="$upgrade">
            <li class="primaryContent upgrade">
                    <form action="{$payPalUrl}" method="post" class="upgradeForm">
                        <div class="cost">{$upgrade.costPhrase}</div>
                        <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
                                
                            <input type="hidden" name="cmd" value="_xclick-subscriptions" />
                            <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
                            <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
                            <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
                            <input type="hidden" name="src" value="1" />
                            <input type="hidden" name="sra" value="1" />
                            
                            <input type="submit" value="{xen:phrase subscribe}" class="button" />
                        <xen:else />
                            <input type="hidden" name="cmd" value="_xclick" />
                            <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
                            
                            <input type="submit" value="{xen:phrase purchase}" class="button" />
                        </xen:if>
                        
                        <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
                        <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
                        <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
                        <input type="hidden" name="quantity" value="1" />
                        <input type="hidden" name="no_note" value="1" />
                        <input type="hidden" name="no_shipping" value="1" />
                        <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
                        
                        <input type="hidden" name="charset" value="utf-8" />
                        <input type="hidden" name="email" value="{$visitor.email}" />
                        
                        <input type="hidden" name="return" value="{xen:link 'full:account/upgrade-purchase'}" />
                        <input type="hidden" name="cancel_return" value="{xen:link 'full:index'}" />
                        <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
                    </form>
                    
                    <div class="upgradeMain">
                        <h4 class="title">{$upgrade.title}</h4>
                        <xen:if is="{$upgrade.description}">
                            <div class="description">{xen:raw $upgrade.description}</div>
                        </xen:if>
                    </div>
            </li>
        </xen:foreach>
        </ul>
    </div>
</xen:if>

<xen:if is="{$purchased}">
    <div class="section">
        <h3 class="subHeading">{xen:phrase purchased_upgrades}</h3>
        <ul>
        <xen:foreach loop="$purchased" value="$upgrade">
            <li class="primaryContent">
                <div class="upgrade">                    
                    <div class="upgradeForm">
                        <xen:if is="{$upgrade.record.end_date}">
                            <div>{xen:phrase expires}: <xen:datetime time="$upgrade.record.end_date" /></div>
                        </xen:if>
                        <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
                            <a href="{$payPalUrl}?cmd=_manage-paylist" class="button">{xen:phrase cancel_subscription}</a>
                        </xen:if>
                    </div>
                    
                    <div class="upgradeMain">
                        <h4 class="title">{$upgrade.title}</h4>
                        <xen:if is="{$upgrade.description}">
                            <div class="description">{xen:raw $upgrade.description}</div>
                        </xen:if>
                    </div>
                </div>
            </li>
        </xen:foreach>
        </ul>
    </div>
</xen:if>
 
Add after
HTML:
<xen:foreach loop="$available" value="$upgrade">
:
HTML:
<xen:if is="$upgrade.user_upgrade_id == subA AND !{xen:helper ismemberof, $visitor, A}">
    //do nothing in this case
<xen:elseif is="$upgrade.user_upgrade_id == subB AND !{xen:helper ismemberof, $visitor, B}" />
    //do nothing aswell
<xen:else />
Add </xen:if> before </xen:foreach>
And don't forget to change the 4 values
 
Add after
HTML:
<xen:foreach loop="$available" value="$upgrade">
:
HTML:
<xen:if is="$upgrade.user_upgrade_id == subA AND !{xen:helper ismemberof, $visitor, A}">
    //do nothing in this case
<xen:elseif is="$upgrade.user_upgrade_id == subB AND !{xen:helper ismemberof, $visitor, B}" />
    //do nothing aswell
<xen:else />
Add </xen:if> before </xen:foreach>
And don't forget to change the 4 values
Tried this and got error on line 10 which is
<xen:if is="$upgrade.user_upgrade_id == subA AND !{xen:helper ismemberof, $visitor, A}">

The following templates contained errors and were not saved: account_upgrades: account_upgrades - Line 10: Invalid condition expression
 
full edited template
Code:
<xen:title>{xen:phrase account_upgrades}</xen:title>

<xen:require css="account_upgrades.css" />

<xen:if is="{$available}">
    <div class="section">
        <h3 class="subHeading">{xen:phrase available_upgrades}</h3>
        <ul>
        <xen:foreach loop="$available" value="$upgrade">
        <xen:if is="$upgrade.user_upgrade_id == 3 AND !{xen:helper ismemberof, $visitor, 9}">
                //do nothing in this case
                <xen:elseif is="$upgrade.user_upgrade_id == 5 AND !{xen:helper ismemberof, $visitor, 10}" />
                //do nothing as well
                <xen:else />
            <li class="primaryContent upgrade">
                    <form action="{$payPalUrl}" method="post" class="upgradeForm">
                        <div class="cost">{$upgrade.costPhrase}</div>
                        <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
                                
                            <input type="hidden" name="cmd" value="_xclick-subscriptions" />
                            <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
                            <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
                            <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
                            <input type="hidden" name="src" value="1" />
                            <input type="hidden" name="sra" value="1" />
                            
                            <input type="submit" value="{xen:phrase subscribe}" class="button" />
                        <xen:else />
                            <input type="hidden" name="cmd" value="_xclick" />
                            <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
                            
                            <input type="submit" value="{xen:phrase purchase}" class="button" />
                        </xen:if>
                        
                        <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
                        <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
                        <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
                        <input type="hidden" name="quantity" value="1" />
                        <input type="hidden" name="no_note" value="1" />
                        <input type="hidden" name="no_shipping" value="1" />
                        <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
                        
                        <input type="hidden" name="charset" value="utf-8" />
                        <input type="hidden" name="email" value="{$visitor.email}" />
                        
                        <input type="hidden" name="return" value="{xen:link 'full:account/upgrade-purchase'}" />
                        <input type="hidden" name="cancel_return" value="{xen:link 'full:index'}" />
                        <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
                    </form>
                    
                    <div class="upgradeMain">
                        <h4 class="title">{$upgrade.title}</h4>
                        <xen:if is="{$upgrade.description}">
                            <div class="description">{xen:raw $upgrade.description}</div>
                        </xen:if>
                    </div>
            </li>
        </xen:if>
        </xen:foreach>
        </ul>
    </div>
</xen:if>

<xen:if is="{$purchased}">
    <div class="section">
        <h3 class="subHeading">{xen:phrase purchased_upgrades}</h3>
        <ul>
        <xen:foreach loop="$purchased" value="$upgrade">
            <li class="primaryContent">
                <div class="upgrade">                    
                    <div class="upgradeForm">
                        <xen:if is="{$upgrade.record.end_date}">
                            <div>{xen:phrase expires}: <xen:datetime time="$upgrade.record.end_date" /></div>
                        </xen:if>
                        <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
                            <a href="{$payPalUrl}?cmd=_manage-paylist" class="button">{xen:phrase cancel_subscription}</a>
                        </xen:if>
                    </div>
                    
                    <div class="upgradeMain">
                        <h4 class="title">{$upgrade.title}</h4>
                        <xen:if is="{$upgrade.description}">
                            <div class="description">{xen:raw $upgrade.description}</div>
                        </xen:if>
                    </div>
                </div>
            </li>
        </xen:foreach>
        </ul>
    </div>
</xen:if>
 
Yes, no errors now. I will then have to test to make sure it work as expected.
By the way, the //do nothing will display ;)
Again, thanks so much for stepping in when nobody else did (y)
 
Minor changes to tags (you should be able to find them out just by looking at a given template), helpers have been removed, instead there are shortcut functions attached to all kinds of variables (mostly $visitor & $user) or directly callable (like dump($var) instead of {xen:helper dump, $var}).
 
Minor changes to tags (you should be able to find them out just by looking at a given template), helpers have been removed, instead there are shortcut functions attached to all kinds of variables (mostly $visitor & $user) or directly callable (like dump($var) instead of {xen:helper dump, $var}).
Minor edit requested.
I want to hide upgrades that users who already purchased since I want them to purchase only once even if it's already expired.
 
Top Bottom