Jump to content
NagarajB

Can we use HOOK to calculate discounts on product/service ?

Recommended Posts

I want to add the discount on products/service and calculates the total amount of product/service, discount would be applies only on product/service not on addon services and setup fees, could anyone plz help me out on this..?

Share this post


Link to post
Share on other sites

Is there a reason that promotions wouldn't work in this case? You can specify promotion products, so that you don't use addons for this.

Share this post


Link to post
Share on other sites

Apologies.., I would like to add discount on base product/services, discount should not apply on configurable options like Additional IP's, RAM, CPU etc...  

Share this post


Link to post
Share on other sites

this is a long-featured request (5 years and counting now)...

https://requests.whmcs.com/topic/ability-to-exclude-configurable-options-from-promotion-discounts

i'd go along with Tom's suggestion and consider using Promotion Codes for this... obviously, not a percentage discount but try using "Fixed Amounts".

e.g., you know how much the product base price is, so if you want to give 10% off, calculate what that amount would be and use that as the fixed amount value... then whatever the user chooses, with regards to configurable options, will be irrelevant as only the fixed amount will be deducted and not a percentage...

another user suggested, in the thread below, that if you used Product addons instead of configurable options, then they are not discounted, only the base product is.... though you may want to check out the documentation about the differences between PA and CO before going down that road...

I doubt anyone is going to write a hook/addon for this missing feature for free, so if you still think you'll need such an addon, then you might need to post in Service Offers & Requests and pay a developer to write it for you... I'm not aware if anyone has released a similar addon in Marketplace, so I don't believe that there is an existing publicly available solution for this out there.

  • Thanks 1

Share this post


Link to post
Share on other sites

Sorry to hijack this thread, but in the reverse way to what's been suggested,

Could using a promotion hook be reversed to add a secondary tax to an invoice?

Currently for Australia I have GST.

But if we could use a hook to add a reverse 'Promotion' then we could +2% as an additional tax.(Purpose is to charge a fee based on a gateway choice - which has been a request for almost as many years as the above request, so not holding my breath..)

Any help with this is great.

 

Thanks.

 

Share this post


Link to post
Share on other sites
24 minutes ago, wellconnit said:

Could using a promotion hook be reversed to add a secondary tax to an invoice?

there are no promotion hooks. :)

24 minutes ago, wellconnit said:

But if we could use a hook to add a reverse 'Promotion' then we could +2% as an additional tax

hmm, you could create a -2% promo code, which would effectively add 2% to the order, but it would be pointless to add it to a link as the client could just remove it... and if you're going to use a hook to add a fee anyway, it seems overcomplicated to try to manipulate a promotion code for that purpose.

24 minutes ago, wellconnit said:

Purpose is to charge a fee based on a gateway choice.

which would now be illegal in the EU...

24 minutes ago, wellconnit said:

which has been a request for almost as many years as the above request, so not holding my breath.

with it now being illegal, I doubt a UK-based company such as WHMCS, would introduce such a feature - and it's still going to apply in the UK after we leave the EU too.

however, there are at least three Gateway Fee products in Marketplace - so if you really need to do this, there are viable options available. :idea:

Share this post


Link to post
Share on other sites

I can not comment on the legality of it but I think it is doable with hooks.

 

<?php
add_hook('InvoiceChangeGateway', 1, function($vars) {
	// Perform hook code here...
	$invoiceid = $vars['invoiceid'];
	$get_invoice_results = localAPI('GetInvoice', ['invoiceid' => $invoiceid]);
	if ($get_invoice_results->result == 'success') {
		if ($vars['paymentmethod'] == 'CHANGE_ME_expensive_gateway_id') {
			// Add additional gateway fee.
			$invoice_itmes = $get_invoice_results->items->item;
			$number_items = count($invoice_itmes);
			$update_invoice_results = localAPI('UpdateInvoice', ['invoiceid' => $invoiceid, 'itemdescription' => [$number_items => 'Gateway Fee Description'], 'itemamount' => [$number_items => 5.00], 'itemtaxed' => [$number_items => true]]);
			if (!($update_invoice_results->result == 'success')) {
				// We should never get here so notify someone who cares.
			}
		} else {
			// Remove gateway fee from invoice, when client selects alternative gateway.
			// You will need to reverse the above code to remove the gateway fee.
		}
	} else {
		// We should never get here so notify someone who cares.
	}
});

 

I have not tested the above code but that is my suggestion.

I think, if I remember, correctly the code will also only work on PHP 5.4+ ... and should be WHMCS 6.x+ safe.

 

Share this post


Link to post
Share on other sites

Hi @brian!,
Thanks for your response.

I kind've understand the logic that it's probably not that high up WHMCS priority list because they don't allow it in their home country, however the primary language in the UK is also English yet WHMCS displays in various other languages, suggesting that they are happy to not limit their service to what suits the UK only.

https://www.businesscompanion.info/en/quick-guides/pricing-and-payment/payment-surcharges
This site also suggests that you are allowed to surcharge for other forms of payment, e.g. Cash / Cheque / Commercial Debit & Credit Cards.

 

I'm not really a fan of paying for a solution like that, because at any point in time as with the custom API's WHMCS could remove the ability for the third party application to work.

Share this post


Link to post
Share on other sites
7 hours ago, carlswart said:

I can not comment on the legality of it but I think it is doable with hooks.

 


<?php
add_hook('InvoiceChangeGateway', 1, function($vars) {
	// Perform hook code here...
	$invoiceid = $vars['invoiceid'];
	$get_invoice_results = localAPI('GetInvoice', ['invoiceid' => $invoiceid]);
	if ($get_invoice_results->result == 'success') {
		if ($vars['paymentmethod'] == 'CHANGE_ME_expensive_gateway_id') {
			// Add additional gateway fee.
			$invoice_itmes = $get_invoice_results->items->item;
			$number_items = count($invoice_itmes);
			$update_invoice_results = localAPI('UpdateInvoice', ['invoiceid' => $invoiceid, 'itemdescription' => [$number_items => 'Gateway Fee Description'], 'itemamount' => [$number_items => 5.00], 'itemtaxed' => [$number_items => true]]);
			if (!($update_invoice_results->result == 'success')) {
				// We should never get here so notify someone who cares.
			}
		} else {
			// Remove gateway fee from invoice, when client selects alternative gateway.
			// You will need to reverse the above code to remove the gateway fee.
		}
	} else {
		// We should never get here so notify someone who cares.
	}
});

 

I have not tested the above code but that is my suggestion.

I think, if I remember, correctly the code will also only work on PHP 5.4+ ... and should be WHMCS 6.x+ safe.

 

Hi @carlswart,

Completely makes sense. Thanks for posting some assistance ! 

Hopefully I can get it working with the reversal also.

It's a shame it isn't built in functionally to WHMCS though.

Would look much better where the Taxes are listed rather than as a line item.

 

Thanks again for your help ! 

Share this post


Link to post
Share on other sites
1 hour ago, wellconnit said:

I kind've understand the logic that it's probably not that high up WHMCS priority list because they don't allow it in their home country, however the primary language in the UK is also English yet WHMCS displays in various other languages, suggesting that they are happy to not limit their service to what suits the UK only.

they might if the EU passed a law that languages other than EU-based ones were banned lol

but seriously, they wouldn't make a high priority of a function that would be effectively illegal in Europe... the same as they wouldn't (shouldn't) release a version in the future that breaks GDPR.

1 hour ago, wellconnit said:

This site also suggests that you are allowed to surcharge for other forms of payment, e.g. Cash / Cheque / Commercial Debit & Credit Cards.

oh there are ways around everything if you put your mind to it... I guess they'll be non-EU companies out there not abiding by the VAT MOSS rules... hey ho it happens.

1 hour ago, wellconnit said:

I'm not really a fan of paying for a solution like that, because at any point in time as with the custom API's WHMCS could remove the ability for the third party application to work.

occasionally, WHMCS even removes the ability for their own software to work too. :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines