Faizal1 Posted April 12, 2020 Share Posted April 12, 2020 Hi there, Is it possible to restrict a coupon code so it can only be used for a certain payment type? E.g Can only be used if paying via PayPal? Thanks 0 Quote Link to comment Share on other sites More sharing options...
WHMCS ChrisD Posted April 13, 2020 Share Posted April 13, 2020 Hi @Faizal1 Thanks for your post, out of the box, no, it is not possible to restrict a coupon to. a certain payment method I'm afraid 1 Quote Link to comment Share on other sites More sharing options...
Faizal1 Posted April 13, 2020 Author Share Posted April 13, 2020 (edited) Ok, thank you Chris. Will have to rethink the coupons then i guess. Edited April 13, 2020 by Faizal1 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 14, 2020 Share Posted April 14, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Faizal1 Posted April 14, 2020 Author Share Posted April 14, 2020 Oh wow thanks @brian!. That sounds promising. I'm not to familiar with writing hooks but i'll start researching now. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 15, 2020 Share Posted April 15, 2020 20 hours ago, Faizal1 said: That sounds promising. I'm not to familiar with writing hooks but i'll start researching now. 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. 🙂 1 Quote Link to comment Share on other sites More sharing options...
Faizal1 Posted April 15, 2020 Author Share Posted April 15, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 15, 2020 Share Posted April 15, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Faizal1 Posted April 15, 2020 Author Share Posted April 15, 2020 You are AWESOME @brian!. That's exactly what i needed and it worked perfectly. I can't thank you enough. 👍👍 0 Quote Link to comment Share on other sites More sharing options...
men83 Posted April 18, 2020 Share Posted April 18, 2020 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 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 22, 2020 Share Posted April 22, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Kelby Posted May 6, 2020 Share Posted May 6, 2020 Hello, Is there any way to give automatique discount if a user choose Paypal to pay in the final step? Thank you 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 7, 2020 Share Posted May 7, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.