Jump to content

Hook to change product


Ragonz

Recommended Posts

I'm wondering if this is possible

We have a trial product setup for some of our products so users can test the service out before comitting to buying. However what we have seen is that people who have already had a trial obviously cant use the trial price override again so my question is

Is it possible to have a hook that sees the trial code has been attempted to been used but the client has already used it and changes the product ordered?

ie. user order product id 438 but whmcs sees that the trial code is not valid for this user so when they click order and pay the invoice it actually orders product id 437

Link to comment
Share on other sites

55 minutes ago, Kian said:

Of course it's possible.

but that wouldn't switch the product in the cart - which is the whole point of the question.

On 11/03/2020 at 15:13, Ragonz said:

Is it possible to have a hook that sees the trial code has been attempted to been used but the client has already used it and changes the product ordered?

yes... though it gets nuanced depending on exactly what you want to do... e.g do you just want to redirect the user from product x to product y (e.g literally preventing them from ordering y), or do you literally mean that you change the product already added (and configured) to the cart... if so, then you get into the realms of a client possibly thinking that they're ordering product a, but now getting product b (I don't know if there is a cost difference between these two products).

2 hours ago, Ragonz said:

I'm going to assume given the lack of responses this isn't possible which is a shame. 

or just very few people here who are likely to reply to such threads... it was on my list of threads to answer - it's doable, it's just a case of clarifying what it is exactly you're wanting to do.

Link to comment
Share on other sites

So there would not be a price difference between the product (because the trial would charge them anyway because the trial code would not apply)

Its just to prevent their paid service from terminating because its still classed as a trial and therefore on the fixed termination .

Link to comment
Share on other sites

  • 5 months later...

I'm back on trying to find a way to do this, trial product is product 431, the none trial product is 430 the hook just needs to swap what product has been purchased if the account has already used the trial code "trial"

alternativly a way to display a big popup message when people go to buy saying "YOU HAVE ALREADY USED THE TRIAL, THIS WILL BILL YOU" because people are idiots and don't read unless its right in their face and massive.

Link to comment
Share on other sites

16 hours ago, Ragonz said:

I'm back on trying to find a way to do this, trial product is product 431, the none trial product is 430 the hook just needs to swap what product has been purchased if the account has already used the trial code "trial"

swapping the product isn't the difficult bit, the pain is working out when you can best do it and the consequences of that timing... for example, if the client was logged in before they followed your trial link, then it's simple... actually, the sooner they're logged in, the more options you have, but sadly you can't do anything until they login.

if they were logged in on your site, then you could hide the trial links from your games pages if they've already used a trial, or if you showed the products in the cart, then the trials products could be hidden (I know you don't).

a checkout validation hook would work and could swap the products given the correct conditions, before the invoice is sent to the client.... though the config options and addons used in each trial/full product would ideally need to be the same - otherwise the swap coding could get very involved.

btw - I assume the trial promocode is configured as only one use per client ?

16 hours ago, Ragonz said:

alternatively a way to display a big popup message when people go to buy saying "YOU HAVE ALREADY USED THE TRIAL, THIS WILL BILL YOU" because people are idiots and don't read unless its right in their face and massive.

a cart validation hook can return an error to the checkout page - actually, it could change the product and/or show an error giving your message and that if they checkout, they will not be getting a trial product.

of course, the thought that always occurs to me with things like this would be that the user could just create a new account each time they want a new trial.

Link to comment
Share on other sites

Clients have to register/login before they can clikc the checkout button if I remember correctly

Trials and full products are pretty much the same thing except for a couple of config options but if they stay not there like they are in the trial I'm not fussed

Promocode is indeed 1 per client

creating a new account we are aware will "game" the system but its a minority of users and most people won't due to our particular setup.

Link to comment
Share on other sites

I don't if this helps but weeks ago I coded an hook that allows to provide "one-off" products/services. Simply put if I already ordered and used your product ID 431 (the trial) I can't purchase it again. If a customer tries to place the order the hook removes it from WHMCS cart showing a modal on screen.

Link to comment
Share on other sites

@Kian The way we do trials currently is that the customer has to contact us and we use the upgrade/downgrade system to change them to a full product, therefore I don't think this hook will work as there is nothing left in their account thats a trial product, unless the hook could see if that account has already used a specific promotion code then apply actions?

Link to comment
Share on other sites

17 hours ago, Ragonz said:

Clients have to register/login before they can click the checkout button if I remember correctly

true - I just wish they were logging in earlier as that gives so many more options.

17 hours ago, Ragonz said:

Trials and full products are pretty much the same thing except for a couple of config options but if they stay not there like they are in the trial I'm not fussed

"pretty much" is the worrying part - swapping basic products in the cart is easy enough, but when you have two products that might have slightly different addons or config options, and then working out a simple way for a user to map optionally replacing some with other options... oh boy.

14 hours ago, Kian said:

I don't if this helps but weeks ago I coded an hook that allows to provide "one-off" products/services.

as an aside, I must say that i'm really warming to your, lets say 'liberal' interpretation of the rules here, where you know that you can't link to your own products, or add links/email in posted hook code, but you're quite happily circumventing that by linking to hooks on GitHub that often, and openly, include advertising/self-promotion links to your commercial products in their descriptions.

I wouldn't expect TPTB to notice that's going on, even though it's potentially damaging to one of the core features (certainly spirit) of this place (e.g, content off-site), so carry on my friend! thanks.png

no doubt your primary reason for using GitHub is to allow easy editing of the hook code, which after a certain amount of time here would not be possible for code included in a post... with a secondary reason being to have the hooks all located in one place... similarly for adding links to them in your club.

i've long had a private repository of all my hooks, both free and commercial, but linking to GitHub makes more sense than posting code here - for many reasons that we needed go into! what's good for the goose is indeed good for the gander. 🙊

14 hours ago, Kian said:

Simply put if I already ordered and used your product ID 431 (the trial) I can't purchase it again. If a customer tries to place the order the hook removes it from WHMCS cart showing a modal on screen.

it sounds a slightly different interpretation in that they can't order a trial more than once - not just of the same trial game, but any trial game product.

14 hours ago, Ragonz said:

unless the hook could see if that account has already used a specific promotion code then apply actions?

that's the way I would go - at checkout validation (when you know they'll be logged in), run a query to see if the current user has used that particular promo code (you'll use it's iD) and if so, thrown an alert error back to checkout... i'd be surprised if that's more than a 5 line function in a hook...  in these circumstances, I don't think I would switch the products in the cart.

I suppose another way to do it would be a variation of Kian's client group hook where if a client has used a trial game product, they're moved to a particular client group - that way you only have to detect if they're a member of the group before denying secondary trials - the issue there would be a client can only be in one group, so might not be a usable option if you're applying CG under other conditions too....

possibly a client custom field (admin only) can be set when they've ordered a trial product and then that can easily be checked if you don't think the hosting table will contain all references if trial products have been upgraded to full.

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