Jump to content

Get the service and domain name before cart


Recommended Posts

Hello,

using the whmcs hook system we want to get the domain address and products id before our customer place the order When does the hook named "ShoppingCartValidateCheckout" work?

exactly what we want When a hosting order arrives, we want to give an error message if the package is pid = 17 and the domain address has been used on this package before. We share a sample code blog below. Can you help?

$cart = $_SESSION['cart'];
$products = [];
$tlds = [];

foreach ($vars['products'] as $product) 
{
    $products[] = $product['pid'];
}

foreach ($vars['domains'] as $domain)
{
    $tlds[] = $domain['domain'];
}


if (in_array(17, $products) && in_array('testantpi.net', $tlds))
{

return array("Error this domain address cannot be used");
}
}); //hook

Best Regards.

Link to comment
Share on other sites

On 15/07/2020 at 14:11, Durukan Bal said:

using the whmcs hook system we want to get the domain address and products id before our customer place the order When does the hook named "ShoppingCartValidateCheckout" work?

https://developers.whmcs.com/hooks-reference/shopping-cart/#shoppingcartvalidatecheckout

Quote

Executes on checkout via the shopping cart.

in other words, after they press the "Complete Order" button at checkout.

On 15/07/2020 at 14:11, Durukan Bal said:

exactly what we want When a hosting order arrives, we want to give an error message if the package is pid = 17 and the domain address has been used on this package before.

<?php

# Product Limiter Hook
# Written by brian!

use WHMCS\Database\Capsule;

add_hook('ShoppingCartValidateCheckout', 1, function($vars) {
	$products = $_SESSION['cart']['products'];
	foreach ($products as $key => $product) {
		if ($product['pid'] == '17') {
			$existingdomain = Capsule::table('tblhosting')->where('packageid','17')->where('domain',$product['domain'])->count();
			if ($existingdomain > 0) {
				return 'Error this domain address cannot be used';
			}
		}
	}
});

possibly, that error text should use a language string instead - but if your site only has one languages, then that's irrelevant.

Link to comment
Share on other sites

18 hours ago, brian! said:

https://developers.whmcs.com/hooks-reference/shopping-cart/#shoppingcartvalidatecheckout

in other words, after they press the "Complete Order" button at checkout.


<?php

# Product Limiter Hook
# Written by brian!

use WHMCS\Database\Capsule;

add_hook('ShoppingCartValidateCheckout', 1, function($vars) {
	$products = $_SESSION['cart']['products'];
	foreach ($products as $key => $product) {
		if ($product['pid'] == '17') {
			$existingdomain = Capsule::table('tblhosting')->where('packageid','17')->where('domain',$product['domain'])->count();
			if ($existingdomain > 0) {
				return 'Error this domain address cannot be used';
			}
		}
	}
});

possibly, that error text should use a language string instead - but if your site only has one languages, then that's irrelevant.


Thank you so much , your software technique is very nice, If you need antpi.net web hosting service, please do not hesitate to contact us. Best Regards.


 


 

Thank you so much , your software technique is very nice, If you need antpi.net web hosting service, please do not hesitate to contact us. Best Regards.

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