Jump to content

Applying 50% Lifetime discount on a product and then applying 50% off first month on that same product


silidrone

Recommended Posts

Hi, I am trying to provide my customers with 50% on specific products for lifetime with a specific coupon. Now, I also want to (disconnectedly of this) have 50% off for the first month on those specific products. So if my product costs $10 normally, for a customer with the lifetime discount coupon code, it would cost $2.5 first month and then $5 dollars for the rest of their life. How can I accomplish this? Usually I had 50% off first month as a coupon, and 50% for lifetime as a coupon as well, but I understand two coupons cannot be applied to one product. So is there a workaround to accomplish this? 

Link to comment
Share on other sites

On 05/03/2020 at 08:31, silidrone said:

So is there a workaround to accomplish this?  

i'm struggling to think of a way to do this from settings - not least because this really is trying to use two different promo codes.

  1. you could duplicate and hide these products, price them at the discounted rate and give the links to them to specific users - then you would only need to use the promocode for the first month discount... though anyone could then use those links if they become known.
  2. you could use an action hook to create a negative setup fee for these specific products if the promocode is being successfully applied... you can't have negative setup fees from settings, but you can bypass that with hooks, so a -2.50 setup fee would effectively be a 2.50 discount for the first month only.
  3. there is the Discount Center addon from ModulesGarden that might be able to do what you want - there may be other applicable addon modules in Marketplace, but none spring to mind.

possibly there is a really simple solution that i'm totally missing.... 🙄

Link to comment
Share on other sites

Hi,
First of all, thank you for trying to help me out!

I see how the 1st option could be done, but I feel like it isnt flexible enough, so I decided to go with the 2nd option you provided, adding a hook.

I added a hook in hooks.php, the file looks like (public/customers/modules/addons/hooks.php):
 

<?php

use WHMCS\Session;

add_hook('OrderProductPricingOverride', 1, function($vars) {
    return ['setup' => '-5.00'];
});

But the thing is, I want it to be 50% off, and the only way I can see this being done is somehow to access to current price of the product. Is that possible via the $vars object (array)? If I am doing anything wrong so far, please warn me.

Link to comment
Share on other sites

I figured out how to get product price by product id from the $vars object and thus wrote this code:
 

<?php

use WHMCS\Session;
use WHMCS\Product;


add_hook('OrderProductPricingOverride', 1, function($vars) {
    $pid = $vars['pid'];
    $command = 'GetProducts';
    $postData = array(
        'pid' => $pid,
    );
    $result = localAPI($command, $postData);
    $price = $result['products']['product'][0]['pricing']['USD']['monthly'];

    return ['setup' => strval(-$price/2)];
});

Everything seems to be working but I am a bit disturbed by the fact that it says Setup Fee: -$... (where ... is the discount amount returned by my hook) in the configure order page, but I'm guessing that is not possible to change to First Month Discount or any text I would like. If it is though, I'd be happy to hear how. Thanks for helping me so far!

Link to comment
Share on other sites

On 10/03/2020 at 11:00, silidrone said:

I added a hook in hooks.php, the file looks like (public/customers/modules/addons/hooks.php):

they would usually go in /includes/hooks

On 10/03/2020 at 12:12, silidrone said:

I figured out how to get product price by product id from the $vars object

it's worth adding something that isn't mentioned in the docs, but the hook point doesn't know what the current cart currency is, so you've got to be careful when overriding prices in this way that you're applying the correct discount per currency... obviously, if you only have USD in your WHMCS, then this isn't relevant.

also, as currently written, it's going to apply to all products... but I assume you're just testing the process for now.

On 10/03/2020 at 12:12, silidrone said:

Everything seems to be working but I am a bit disturbed by the fact that it says Setup Fee: -$... (where ... is the discount amount returned by my hook) in the configure order page, but I'm guessing that is not possible to change to First Month Discount or any text I would like.

the complexity of doing that depends on whether you're using "normal" (positive) setup fees on other products - if not, then perhaps a simple Language Override would be sufficient and you can change the "Setup Fees" text to whatever you like (and ideally remember to do it for all languages that your WHMCS uses)...

$_LANG['cartsetupfees'] = "First Month Discount";

4mrmF4R.png

if you are using setup fees "normally" elsewhere, then perhaps an if statement within ordersummary.tpl based on whether a specific promo code is being used... if it is, then it shows FMD, if not, is shows setup fees.

Link to comment
Share on other sites

Hi,

Yes indeed I only have USD and I decided to go with the language overriding as I am not using Setup Fees anywhere else in my WHMCS, now I am satisfied with how it looks, I do realize it's really hacky, but it does the job.

Thank you for your help, have a great day!

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.

×
×
  • 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