Disable ot_coupon when freeoptions?...
ZC version 1.5.6c
I'm in need to trigger an error message and somehow disable ot_coupon from accepting a particular coupon code, or moving forward with the checkout process when said code has been entered. In other words, if client wants free shipping, client cannot use that discount code. If clients wants to use discount code, client cannot get free shipping.
Is something like this possible?
Re: Disable ot_coupon when freeoptions?...
This always happens to me. I put my head on the pillow for the night (it's almost 4am) and my brain remembers something that could work, so I have to get out of bed and try it.
For anyone else having a similar issue, add the following to ot_coupon around line 267
Code:
// bof: disable discount coupons on free shipping
if (substr_count($_SESSION['shipping']['id'], 'freeoptions') !=0) {
$foundvalid = false;
}
// eof: disable discount coupons on free shipping
if (!$foundvalid) {
$this->clear_posts();
}
This isn't specific for any particular coupon code but for the time being works. What this does is remove the discount coupon or not allow any coupon code to be entered when free shipping is selected. There is an error message that gets triggered, just change it to suit your needs languages>english.php the define is TEXT_INVALID_COUPON_PRODUCT.
Now I can sleep. :blush:
Re: Disable ot_coupon when freeoptions?...
Interesting suggestion. It might also be good to verify that $_SESSION['shipping']['id'] is not empty before checking it just to be sure.
Re: Disable ot_coupon when freeoptions?...
Quote:
Originally Posted by
swguy
Interesting suggestion. It might also be good to verify that $_SESSION['shipping']['id'] is not empty before checking it just to be sure.
I can't take credit for the code. I found something similar a few years back on the forum (I don't remember who posted it) and implemented a version of it on one of my modules. So I remembered this morning I had done something similar to what I needed and reused it. 99% of the time I have no clue what I'm doing and my php knowledge is quite limited, but I manage after a boat load of hours of browsing this wonderful forum :smile:
I use the native zc checkout, which by default requires shipping to be selected before moving forward to add coupons and payments. Wouldn't this sequence imply that $_SESSION['shipping']['id'] is never empty by the time customer enters a coupon code? If not, how do I go about to verify that $_SESSION['shipping']['id'] is not empty?
Thank you!
Re: Disable ot_coupon when freeoptions?...
It's really just an antibugging step. Strictly speaking in most cases (especially success path) it wouldn't be needed. You would just change
if (substr_count($_SESSION['shipping']['id'], 'freeoptions') !=0) {
to
if (!empty($_SESSION['shipping']['id']) && substr_count($_SESSION['shipping']['id'], 'freeoptions') !=0) {
Re: Disable ot_coupon when freeoptions?...
Quote:
Originally Posted by
swguy
It's really just an antibugging step. Strictly speaking in most cases (especially success path) it wouldn't be needed. You would just change
if (substr_count($_SESSION['shipping']['id'], 'freeoptions') !=0) {
to
if (!empty($_SESSION['shipping']['id']) && substr_count($_SESSION['shipping']['id'], 'freeoptions') !=0) {
Thank you so much! I'll make the change then!
Happy New Year! :smile: