Jump to content

Coupon codes


aspidagrant

Recommended Posts

Is there a way to display certain info/text when a coupon is used? I know in the LANG folder you can change the saying for a promo:

 

$_LANG['orderpromopriceoverride'] = "Price Override";

 

But I am wanting it to say something specific for a certain coupon. For instance, the coupon code "one" will allow our clients to get 6 months for $1, and then the regular price will be enabled. I would prefer for the text to mention that.

 

The issue is that we will also use other promo codes so I do not want to have the override say the same thing for every coupon.

 

Thanks for the help.

Link to comment
Share on other sites

to do something like this you will likely need to edit the order-form templates - possibly only viewcart.tpl, but that will depend on where you want the text to be, and which order-form template you're using.

 

e.g, in "Modern" viewcart.tpl displays the promotional code message between the subtotal and total..

 

{if $promotioncode}
<tr class="promotion"><td class="textright">{$promotiondescription}:  </td><td class="textcenter">{$discount}</td></tr>
{/if}

so for you using this promo code, that might say $1.00 Price Override:

 

you can replace (or add to) this by modifying the above line...

 

{if $promotioncode}
<tr class="promotion"><td class="textright">{if $promotioncode eq "one"}6 months for $1{else}{$promotiondescription}{/if}:  </td><td class="textcenter">{$discount}</td></tr>{/if}

so if someone uses the "one" coupon code, they should now only see "6 months for $1", for any other coupons, they should see the usual text.

 

if you are using multiple languages on whmcs, then it would be easier to use language overrides and define the message for each language in the override file and then call that language variable in the code...

 

$_LANG['couponcodeone'] = "6 months for $1";

 

{if $promotioncode}
<tr class="promotion"><td class="textright">{if $promotioncode eq "one"}{$LANG.couponcodeone}{else}{$promotiondescription}{/if}:  </td><td class="textcenter">{$discount}</td></tr>{/if}

so if you then wanted to use this for multiple promo codes, there are (at least) two options...

 

either you can use multiple {if} statements - so imagine a second couple code "fred" and assume we've already setup its text string in the language override file..

 

{if $promotioncode}
<tr class="promotion"><td class="textright">{if $promotioncode eq "one"}{$LANG.couponcodeone}{elseif  $promotioncode eq "fred"}{$LANG.couponcodefred}{else}{$promotiondescription}{/if}:  </td><td   class="textcenter">{$discount}</td></tr>{/if}

the alternative solution is simpler, but made slightly complicated by your promo code being "one" - as that runs the risk of there being a value for "one" in the language files - I don't think there is, but i'm assuming your other promo codes are similar type words, it's better safe than sorry.. :)

 

the simplest way to use this solution for anyone else would be to, in the language override files, just use the coupon names... so say you had a promo code, "6for1"...

 

$_LANG['6for1'] = "6 months for $1";

 

{if $promotioncode}
<tr class="promotion"><td class="textright">{if $LANG.$promotioncode}{$LANG.$promotioncode}{else}{$promotiondescription}{/if}:  </td><td class="textcenter">{$discount}</td></tr>{/if}

so this will check if there is a language variable in the override file for the promo code being used - if so, it uses it, if not it defaults to the standard text... that way, there should always be something displayed.

 

but for you, because you may only be using one word coupon codes that might be already used in the language files, we have to go the extra yard/metre/mile etc...

 

{if $promotioncode}
<tr class="promotion"><td class="textright">{assign var="couponname" value="couponcode"|cat:$promotioncode|strtolower}{if $LANG.$couponname}{$LANG.$couponname}{else}{$promotiondescription}{/if}:  </td><td class="textcenter">{$discount}</td></tr>
{/if}

so the first thing the code does (if there is a promo code being used) is to create a new variable called couponname and give it a value of "couponcode"+(the promotion code) - so if the promo code is "one", $couponname will equal "couponcodeone".

 

additionally, because this new variable is case-sensitive (but the coupon codes themselves are not), we convert the new variable to lowercase using strtolower (you could convert to uppercase using strtoupper if you wish) - the point being, that while "one" would work fine, without this additional code, "OnE" would fail to show the correct text - the coupon code would still be applied to the cart, but the specific text for that coupon would not be shown.

 

next it checks to see if there is a value for this couponname variable in the language file - if so, it shows it, and as before if it doesn't exist, it just defaults to the usual text for that type or promo code.

 

anyway, that's the basic idea - but you should be able to display this text wherever you want on the page as long as that page has access to the $promotioncode variable.

 

hope that helps.

Edited by brian!
Link to comment
Share on other sites

  • 3 weeks later...

@brian! - Thank you so much for the detailed info. I apologize for the delay, we had some other things come up that took authority over this.

 

I was trying to edit this and it is not working properly. I am not using a built in WHMCS order form, it is a custom one. I will only be using 1 coupon code that will automatically be applied to every order. This is the promo code line:

 

<strong>{$LANG.orderpromotioncode}:</strong> {if $promotioncode}{$promotioncode} - {$promotiondescription}<br /><a href="{$smarty.server.PHP_SELF}?a=removepromo">{$LANG.orderdontusepromo}</a>{else}

 

I tried using this:

 

<strong>{$LANG.orderpromotioncode}:</strong> {if $promotioncode}{$promotioncode} - {if $promotioncode eq "ASPIDA"}6 months for $1{else}{$promotiondescription}<br /><a href="{$smarty.server.PHP_SELF}?a=removepromo">{$LANG.orderdontusepromo}</a>{else}

 

I changed the promo code to 'ASPIDA' to avoid any errors with "one".

 

Any idea why this would not work?

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