Jump to content

Offer a discount once per domain


Craft

Recommended Posts

27 minutes ago, brian! said:

on a service related to the domain, or on domain registration itself ??

A service related to the domain (Web Hosting)

I need to offer a free trial period for a web hosting plan but I need the customer could only use it once per domain.

 

Link to comment
Share on other sites

14 hours ago, Craft said:

Any update?

I couldn't think of an existing solution - commercial or otherwise.... possibly one of Kian's hooks could have been expanded to cover this, but it doesn't work in v8 anyway even before you could think about expanding it. 🙄

all you should need is a domain validation hook that checks the domain entered when used with specific products...

<?php

# Prevent Domain Re-Use with Trial Products Hook
# Written by brian!

use WHMCS\Database\Capsule;

add_hook('ShoppingCartValidateDomain', 1, function($vars) {
	
	$pid = $_SESSION["cart"]["domainoptionspid"];
	$trialproducts = array(44);
	$domain = $vars['sld'].$vars['tld'];
	$domaincheck = Capsule::table('tblhosting')->where('packageid',$pid)->where('domain',$domain)->count();
	if(in_array($pid,$trialproducts) && $domaincheck > 0) {
		return 'You cannot use this trial service with '.$domain;
	}
});
On 28/10/2020 at 14:53, Craft said:

I need to offer a free trial period for a web hosting plan but I need the customer could only use it once per domain.

so in the above hook, $trialproducts should contain a list of your trial product IDs and then the hook checks if there is a record in the hosting database for that product AND domain... if yes, then it throws an error message and prevents the ordering continuing.

as written, it's only going to check for the current PID in the database, .e.g let's say you had 2 trial products (44 & 45) and someone had previously used domain.com with PID#44... the hook would prevent them using the domain again with #44, but wouldn't stop them using it with #45.... now you may or may not want that to happen

if you don't, e.g you want to prevent a domain being re-used after it's been used on ANY listed trial service, then that's just a tweak to the query changing the first where condition to a wherein.

	$domaincheck = Capsule::table('tblhosting')->whereIn('packageid',$trialproducts)->where('domain',$domain)->count();

the error message thrown could use a language string if you prefer to ensure that it's shown in the user's language.

Link to comment
Share on other sites

8 hours ago, brian! said:

I couldn't think of an existing solution - commercial or otherwise.... possibly one of Kian's hooks could have been expanded to cover this, but it doesn't work in v8 anyway even before you could think about expanding it. 🙄

 

Are you sure that this hook doesn't work in v8?

Then this hook is useless 🙂

Link to comment
Share on other sites

11 hours ago, Craft said:

Are you sure that this hook doesn't work in v8?

the hook I posted works in v8, and I see no reason why it wouldn't work in v7.... I was saying that when I tested Kian's hook previously, it didn't work in v8 (but did in v7).

11 hours ago, Craft said:

Then this hook is useless 🙂

i'm not in the habit of posting useless hooks - I can leave that to others. 😜

Link to comment
Share on other sites

4 hours ago, brian! said:

the hook I posted works in v8, and I see no reason why it wouldn't work in v7.... I was saying that when I tested Kian's hook previously, it didn't work in v8 (but did in v7).

i'm not in the habit of posting useless hooks - I can leave that to others. 😜

I thought it doesn't work in v8 so I thought it's useless, but if it works in v8 then it's very useful 🙂

I'll try it and give you my feedback, thanks in advance 🙂

 

Link to comment
Share on other sites

  • 2 weeks later...

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