Jump to content

Possible to restrict coupon use to payment type?


Faizal1

Recommended Posts

using an action hook, you could prevent checkout if your condition(s) weren't met, e.g if specific promocode and paypal used, stop checkout process and display visual warning that they can't use that combination and ask them to either change gateway choice or remove promocode from cart.

 

Link to comment
Share on other sites

6 minutes ago, brian! said:

ShoppingCartValidateCheckout is the one i'm thinking of - at it's most basic, it's going to take less than a handful lines of PHP code. 🙂

Thanks again Brian. I found another post with the 'Check For Promo Code Hook' code posted by you and that part looks great. Now i'm trying to figure out how to adapt that but I have no idea about php code really but only one way to learn so will see what i can come up with.

Link to comment
Share on other sites

23 minutes ago, Faizal1 said:

I found another post with the 'Check For Promo Code Hook' code posted by you and that part looks great.

it's a good starting point... 🙂

24 minutes ago, Faizal1 said:

Now i'm trying to figure out how to adapt that but I have no idea about php code really but only one way to learn so will see what i can come up with.

at the most basic, the hook below would work - it should just need to change the promocode from "basic" to your promotion code name; and the paymentmethod to your paypal gateway name (there are a few PP gateways now, so you will need to choose the name of yours).

<?php

add_hook('ShoppingCartValidateCheckout', 1, function ($vars) {
	$promocode = $vars['promocode'];
	$paymentmethod = $vars['paymentmethod'];
	if ($promocode == "basic" && $paymentmethod == "paypalcheckout") {
		return 'You cannot use Paypal with this promotion code - either change your payment method or <a href="cart.php?a=removepromo">remove</a> the code';
	}
});

ideally, that return should be a language string if your site has multiple languages - but just get it working for now and tweak it after that.

I think for your situation you won't even need to both checking that the promocode exists or is valid, you're just blocking certain promocodes being used with certain gateways regardless of whether they're valid or not.

Link to comment
Share on other sites

Hello ,

I'm a  beginner here and i want to add this option to my whmcs , but i don't know how to add it 

1 - The name of hook well be  hooks.php   or  ShoppingCartValidateCheckout.php 

2- Where i well place the hook  in   templates/orderforms/standard_cart  or in includes/hooks  floders

Many thanks

 

Link to comment
Share on other sites

On 18/04/2020 at 15:54, men83 said:

The name of hook well be  hooks.php   or  ShoppingCartValidateCheckout.php 

you can call it whatever you want to - but the filename must end in .php and contain no spaces...

personally, I wouldn't call it either of the above, i'd give it a memorable name such as promocode_paypal.php

On 18/04/2020 at 15:54, men83 said:

Where i well place the hook  in   templates/orderforms/standard_cart  or in includes/hooks  floders

it should be uploaded to the /includes/hooks folder.

Link to comment
Share on other sites

  • 2 weeks later...
On 06/05/2020 at 12:31, Kelby said:

Is there any way to give automatic discount if a user choose Paypal to pay in the final step? 

not from settings.... there are gateway fees addons available in Marketplace and if any of them allow negative fees/percentages, then that should work for your situation.

you could use hooks, but depending on the paypal gateway, you might not know whether they've used PP until after checkout.

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