Jump to content

Custom Promo Banner In Order Configaration Page


natanray

Recommended Posts

Hello,

I am wondering to know, some providers are showing promo applied banner in order summery page or order configaration page. Like below attachment. They are showing 50% discount applied on order. I know a code which is able to show the promo code: {$smarty.session.cart.promo|strtoupper}

But I am wondering to know, which code able to show discount percentage?

Thanks & Regards,

Natan R.

Screenshot (90).png

Link to comment
Share on other sites

11 minutes ago, natanray said:

I am wondering to know, some providers are showing promo applied banner in order summery page or order configuration page. Like below attachment. They are showing 50% discount applied on order. I know a code which is able to show the promo code: {$smarty.session.cart.promo|strtoupper}

I didn't think it was four years ago when I posted the reply below... 😲

12 minutes ago, natanray said:

But I am wondering to know, which code able to show discount percentage?

hmm... on that page, I doubt there wouldn't be a Smarty or Session variable I think you can access for that info - possible simple solutions might include...

  1. using a language override string based on the promo name.
  2. nesting if statements, e.g if promo equals X, display X message; if promo Y, display Y message.
  3. querying promo value from session in database to get the percentage.
  4. passing the percentage discount in the URL.
  5. not using a promocode but instead employing an override pricing hook.

I like the first and fourth ideas. 😎

Link to comment
Share on other sites

1 hour ago, natanray said:

Can you please explain, how can I do that?

aah - you called my bluff... I was merely speculating that it could be done... 😎

so if we take your code as a starting point...

{if $smarty.session.cart.promo}
	<div class="alert alert-promo" role="alert">
		<div class="alert-body">Hey! You've unlocked <b>{$smarty.session.cart.promo|strtoupper}</b> discount coupon that was automatically applied to your order! Congratulations!
		</div>
	</div>
{/if}

and let's say the promo code is called 'basichosting' and so we create a language override for it...

$_LANG['promocode']['basichosting'] = "Hey! You've unlocked a <b>50%</b> discount deal that was automatically applied to your order! Congratulations!";

and then the template code becomes...

{if $smarty.session.cart.promo && $LANG.promocode.{$smarty.session.cart.promo}}
	<div class="alert alert-promo" role="alert">
		<div class="alert-body">{$LANG.promocode.{$smarty.session.cart.promo}}</div>
	</div>
{/if}

JDtq7ZB.png

basically, it's now checking that a promo code has been applied (though not checking if that promo code is valid) AND there is a language string for it (in the current language)... if either condition isn't true (e.g the user is French, but you don't have an equivalent French string), the message isn't shown.

1 hour ago, natanray said:

Also, How to show this in configure page?

don't be hitting me @ 5pm with questions like this! ☺️

technically, that's not the configure template - it's going to be ordersummary.tpl... but FWIW, I wouldn't suggest changing this output because it's going to get messy, a pain to update and ultimately, you can't guarantee that a valid promo code is being passed... yes, I know you're passing the codes via the URLs, but even so...

let's just take changing the main product price...

<span class="pull-right">{$producttotals.pricing.baseprice}</span>

becomes...

<span class="pull-right">{if $smarty.session.cart.promo}<strike>{$producttotals.pricing.baseprice}</strike><br>{$currency.prefix}{($producttotals.pricing.baseprice->toNumeric()*0.5)|number_format:2}{$currency.suffix}{/if}</span>

e43y7sC.png

but this is just for one product - when you get to multiple products using the same ordersummary template, all with potential different discount rates, then it gets real messy - you'll end up needing to add pid values to the if statements.... actually, in your case to simplify things, you might get away with using gid to check for product groups as it looks like your promo codes are being applied to products within product groups, not a separate promo code for each product...

the above code is for Six, so might have to be slightly tweaked for Lagom - it could be done, but it's going to involve a lot of work.

Link to comment
Share on other sites

20 hours ago, brian! said:

{if $smarty.session.cart.promo && $LANG.promocode.{$smarty.session.cart.promo}} <div class="alert alert-promo" role="alert"> <div class="alert-body">{$LANG.promocode.{$smarty.session.cart.promo}}</div> </div> {/if}

Thanks Brain Once Again, It's Working Fine 😍

20 hours ago, brian! said:

if either condition isn't true (e.g the user is French, but you don't have an equivalent French string), the message isn't shown.

Language Selector can be disabled to avoid this issue :)

20 hours ago, brian! said:

you might get away with using gid to check for product groups as it looks like your promo codes are being applied to products within product groups, not a separate promo code for each product...

How to apply gid in if stetements? I searched about it, but did not find any solutions.

Link to comment
Share on other sites

25 minutes ago, natanray said:

How to apply gid in if stetements? I searched about it, but did not find any solutions.

I will have posted about it before, but in ordersummary, one way to do it would be...

<span class="pull-right">
	{if $smarty.session.cart.promo}
		<strike>{$producttotals.pricing.baseprice}</strike><br>
			{if $producttotals.productinfo.gid eq '1'}
				{assign promodiscount 0.5}
			{elseif $producttotals.productinfo.gid eq '2'}
				{assign promodiscount 0.2}
			{else}
				{assign promodiscount 1}
			{/if}
		{$currency.prefix}{($producttotals.pricing.baseprice->toNumeric()*$promodiscount)|number_format:2}{$currency.suffix}
	{else}
		{$producttotals.pricing.baseprice}
	{/if}
</span>

i've indented the code to make it clearer, but basically what it says is that if the product in ordersummary is from gid #1, then it applies a 50% discount to the main product baseprice; if it's gid #2, then it's 20%; if it's from neither, then the fall back position is to multiply it by 1, e.g give no discount.

Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...
On 8/06/2020 at 10:38 PM, brian! said:

aah - you called my bluff... I was merely speculating that it could be done... 😎

so if we take your code as a starting point...


{if $smarty.session.cart.promo}
	<div class="alert alert-promo" role="alert">
		<div class="alert-body">Hey! You've unlocked <b>{$smarty.session.cart.promo|strtoupper}</b> discount coupon that was automatically applied to your order! Congratulations!
		</div>
	</div>
{/if}

and let's say the promo code is called 'basichosting' and so we create a language override for it...


$_LANG['promocode']['basichosting'] = "Hey! You've unlocked a <b>50%</b> discount deal that was automatically applied to your order! Congratulations!";

and then the template code becomes...


{if $smarty.session.cart.promo && $LANG.promocode.{$smarty.session.cart.promo}}
	<div class="alert alert-promo" role="alert">
		<div class="alert-body">{$LANG.promocode.{$smarty.session.cart.promo}}</div>
	</div>
{/if}

JDtq7ZB.png

basically, it's now checking that a promo code has been applied (though not checking if that promo code is valid) AND there is a language string for it (in the current language)... if either condition isn't true (e.g the user is French, but you don't have an equivalent French string), the message isn't shown.

don't be hitting me @ 5pm with questions like this! ☺️

technically, that's not the configure template - it's going to be ordersummary.tpl... but FWIW, I wouldn't suggest changing this output because it's going to get messy, a pain to update and ultimately, you can't guarantee that a valid promo code is being passed... yes, I know you're passing the codes via the URLs, but even so...

let's just take changing the main product price...


<span class="pull-right">{$producttotals.pricing.baseprice}</span>

becomes...


<span class="pull-right">{if $smarty.session.cart.promo}<strike>{$producttotals.pricing.baseprice}</strike><br>{$currency.prefix}{($producttotals.pricing.baseprice->toNumeric()*0.5)|number_format:2}{$currency.suffix}{/if}</span>

e43y7sC.png

but this is just for one product - when you get to multiple products using the same ordersummary template, all with potential different discount rates, then it gets real messy - you'll end up needing to add pid values to the if statements.... actually, in your case to simplify things, you might get away with using gid to check for product groups as it looks like your promo codes are being applied to products within product groups, not a separate promo code for each product...

the above code is for Six, so might have to be slightly tweaked for Lagom - it could be done, but it's going to involve a lot of work.

Hi @Brain, I have updated WHMCS to 8.0.4 version, and seems this codes are not working anymore with the latest version. Can you please provide some tweaks according to latest update,

Thanks

Link to comment
Share on other sites

1 hour ago, natanray said:

I have updated WHMCS to 8.0.4 version, and seems this codes are not working anymore with the latest version. Can you please provide some tweaks according to latest update,

 the code should still be OK, but with v8, access to the cart session array used in this solution would be disabled by the Smarty Security Policy... specifically the last section at the bottom of the page.

the solution would be to enable it again by adding the code from the docs to your configuration.php file...

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

... and that should enable the code to work again. 🙂

Link to comment
Share on other sites

  • 3 months later...
On 1/12/2020 at 10:47 PM, brian! said:

 the code should still be OK, but with v8, access to the cart session array used in this solution would be disabled by the Smarty Security Policy... specifically the last section at the bottom of the page.

the solution would be to enable it again by adding the code from the docs to your configuration.php file...


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

... and that should enable the code to work again. 🙂

Last time it was worked! But today after updating to latest WHMCS version V8.1.3, the codes again seems stopped working 😞

Do you have any solution?

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...
On 12/2/2020 at 1:17 AM, brian! said:

 the code should still be OK, but with v8, access to the cart session array used in this solution would be disabled by the Smarty Security Policy... specifically the last section at the bottom of the page.

the solution would be to enable it again by adding the code from the docs to your configuration.php file...

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

... and that should enable the code to work again. 🙂

Hi @brian! I added this code on configuration.php but when open checkout page is blank in whmcs 8.5.1

Link to comment
Share on other sites

1 hour ago, kang28ivan said:

Hi @brian! I added this code on configuration.php but when open checkout page is blank in whmcs 8.5.1

Been almost 2 years since Brian stopped regularly participating here, and 2.5 since that was posted. I'd suggest that unless someone else comes up with a solution, you won't be seeing any answers. 😉

Link to comment
Share on other sites

11 minutes ago, bear said:

Been almost 2 years since Brian stopped regularly participating here, and 2.5 since that was posted. I'd suggest that unless someone else comes up with a solution, you won't be seeing any answers. 😉

Oh I see, I just found out Brian has stopped participating

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