Jump to content

Appending billing cycle


twgh

Recommended Posts

Hello everyone,

I wanted to make annual billing cycle my default, so I used the code at the top of my configureproduct.tpl

{if $pricing.annually}{assign 'billingcycle' 'annually'}{/if}

However, I noticed that if I append &billingcycle=monthly, it doesn't work. An example of what I mean below is

 http://mywhmcsinstallation.com/cart.php?billingcycle=monthly 

Is there a way I can default to annual and still append the billingcycle when necessary?

Link to comment
Share on other sites

3 hours ago, twgh said:

Is there a way I can default to annual and still append the billingcycle when necessary?

if the client is choosing a domain with this product, then the code should probably go in configureproductdomain...

{if $smarty.get.billingcycle && in_array(array('monthly','quarterly','semiannually','biennially','triennially'))}{assign "billingcycle" $smarty.get.billingcycle}{else}{assign "billingcycle" "annually"}{/if}

if they're not, then it should work in configureproduct.tpl - however, it is important to note that the use of get in recent releases would now likely break the Smarty Security Policy - if you see that occurring, then you would either have to amend the security policy to allow get, or you use an ClientAreaPageCart hook and move the logic to the hook to return the appropriate variable value.

of course another way would to be tackle this earlier and add your billingcycle value at the products.tpl stage - you could set it to default to using billingcycle=annually in the button and if you ever gave a direct url to a user passing a different cycle, then it would bypass products.tpl and just pass the cycle as normal... if going down that road, you shouldn't need to edit either configureproduct(domain) templates.

Link to comment
Share on other sites

Hi @brian!

Thank you so much for your help. I appreciate it.

So I tried the products.tpl option, as it seems like the fastest way.

However, it won't work if I append monthly billing cycle to the group URL. Any ideas on how to go about this, please?

On 4/03/2021 at 5:56 PM, brian! said:

if the client is choosing a domain with this product, then the code should probably go in configureproductdomain...


{if $smarty.get.billingcycle && in_array(array('monthly','quarterly','semiannually','biennially','triennially'))}{assign "billingcycle" $smarty.get.billingcycle}{else}{assign "billingcycle" "annually"}{/if}

if they're not, then it should work in configureproduct.tpl - however, it is important to note that the use of get in recent releases would now likely break the Smarty Security Policy - if you see that occurring, then you would either have to amend the security policy to allow get, or you use an ClientAreaPageCart hook and move the logic to the hook to return the appropriate variable value.

of course another way would to be tackle this earlier and add your billingcycle value at the products.tpl stage - you could set it to default to using billingcycle=annually in the button and if you ever gave a direct url to a user passing a different cycle, then it would bypass products.tpl and just pass the cycle as normal... if going down that road, you shouldn't need to edit either configureproduct(domain) templates.

 

Edited by twgh
Link to comment
Share on other sites

32 minutes ago, twgh said:

However, it won't work if I append monthly billing cycle to the group URL. Any ideas on how to go about this, please?

I might need to go away and ponder this in a darkened room.... ordinarily, as per above, you could check if there is a billing cycle in the url, but in recent versions and the wonderful decision to redirect gid to slugnames, there's internal redirection occurring and you're losing the bc value.

if you can pass your billingcycle value to the group name instead, then that should work with modified code in products.tpl. e.g,  let's say you have a product group called "hosting" with gid=1, then if your URL was not cart.pgp?gid=1&billingcycle=monthly, but you used...

Quote

index.php/store/hosting?billingcycle=monthly

..or whatever your Friendly URLs equivalent would be for your site...

<a href="{$WEB_ROOT}/cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{if isset($smarty.get.billingcycle)}&billingcycle={$smarty.get.billingcycle}{else}&billingcycle=annually{/if}{/if}" class="btn btn-success btn-sm" id="product{$product@iteration}-order-button">

yes i'm having to use Smarty get again, so the Smarty Security Policy would have to be tweaked to allow it.

$smarty_security_policy = array(
    'system' => array(
        'enabled_special_smarty_vars' => array(
            'get',
        ),
    ),
);

I think the only other way to do it would be with an output hook that tweaked the URL with JS.

Link to comment
Share on other sites

😂😂

1 hour ago, brian! said:

I might need to go away and ponder this in a darkened room....

Let me try this then. I will let you know how it goes.

1 hour ago, brian! said:

I might need to go away and ponder this in a darkened room....

Thank you so much for your help. You are amazing. Don't stay too long in the darkened room

Link to comment
Share on other sites

Hi @brian!,

This worked perfectly. This is so amazing. 

 

2 hours ago, brian! said:

if you can pass your billingcycle value to the group name instead, then that should work with modified code in products.tpl. e.g,  let's say you have a product group called "hosting" with gid=1, then if your URL was not cart.pgp?gid=1&billingcycle=monthly, but you used...

Quote

index.php/store/hosting?billingcycle=monthly

..or whatever your Friendly URLs equivalent would be for your site...


<a href="{$WEB_ROOT}/cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{if isset($smarty.get.billingcycle)}&billingcycle={$smarty.get.billingcycle}{else}&billingcycle=annually{/if}{/if}" class="btn btn-success btn-sm" id="product{$product@iteration}-order-button">

yes i'm having to use Smarty get again, so the Smarty Security Policy would have to be tweaked to allow it.


$smarty_security_policy = array(
    'system' => array(
        'enabled_special_smarty_vars' => array(
            'get',
        ),
    ),
);

Thank you so much for helping us. You really are a huge asset to the community.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated