Simple Coupon Field

Clients want to run a promo with a single coupon code. If a shopper enters the correct code they will upgrade them to second day shipping. I don't need this to reflect anywhere in the product or shipping prices, the client will be handling this. All I want to do is add a single text input field to capture the promo code and let shoppers know if it's accepted or denied....but obviously I don't want the field to be "required".

The field would then pass onto the various confirmation emails so the store owners know who to upgrade (it would even be ok for an invalid code to pass through I guess, because they can make the distinction of valid promo codes on their own).

Trying to rush this since it's a promo running for Mother's Day. Suggestions?

One more question: What is the best method for testing things like this when the site is live? I obviously don't want to change the checkout template prior to testing. Thanks!

1) You can create a coupon with a discount string of 1-0.01. This is a valid coupon that can be added to the cart and will give a discount of one penny. You can name it Shipping Upgrade and then it will be clear when it is present in the cart. Of course, it does require that a penny discount be offered.

2) Unfortunately, a FoxyCart coupon code can't be used if it has no value. You can create a coupon code using a discount string of 0-0 or 1-0 and apply it, but the fact that you have used it on the order is not shown anywhere. If you really don't want to offer a discount, you could "self-host" the "Add a Coupon" field and have users enter the code in the store (client's server) and handle the validation logic on your end. If it is valid, you can add a custom, hidden field to the cart indicating that the coupon is present. This hidden field will be available in your XML datafeed or the transaction details in the FC back-end.

Number 2 sounds pretty decent...although I'm no wizard with figuring out how I would implement that, ha!

I have no problem with running a simple test (unrelated to foxyshop on the client's server) to see if the text in the input field is equal to the discount code we want to use. I'm not even so much concerned about "validating" their entry...nor do I care if this has anything to do with actual "coupons". I just think it would be nice to let the customer know in some way that what they entered was a correct/incorrect promo code. From the shop owners side I just need it to show up in plain text...could even be a "note" on the order. Thoughts??

This assumes you have a code called "moms" and if they enter it correctly it will automatically add a hidden field to the cart that IDs it as having upgraded shipping and alerts them the code is valid. The button would look like this:

I think that might be perfect. The store owners don't really care, they just want the shoppers subscribed to their email updates to have an incentive, it will be a short-run on this promo anyway. Anyone who would think to use "view source" or the like in this situation can have a reward for their efforts THANK YOU! I'll followup if I have additional questions related to this.

Side Question: What is your method for testing changes like this on a live site? I don't typically deal with ecommerce, so I've never had to work/test on "sensitive" pages like the checkout.

Your best bet would be to have a staging server where you can test everything. Barring that, you can always deploy something like this on a "hidden" page that only you have access to before you add it to the whole site.

The button I've provided will need to go on your client's site rather than in the cart or on the checkout page. You might be able to get something up and running on the checkout page, but given that it sounds like you're looking for a quick turnaround, I think this is the best option for the time being.

You can also do a lot of testing using Firebug if you're familiar with that. That impacts only your local environment without risking anything remotely.

I actually just spent the last couple of hours setting up a local testing server on my Mac and threw in the site's WP database. I also created an additional demo store account through foxycart to use with it. Not sure if this method is perfect...but it seems to be running everything and will probably come in handy with request like this in the future.

I will play with some options tomorrow and try to post back what method I used for anyone else looking for something like this.

Worth noting, starting from version 0.7.2 all coupons that have been added to the cart, whether they affect the cart or not, are displayed in the cart listing. So if you're on the latest version of FoxyCart you could utilise the normal coupon entry system for this to work.

Also remember that if you are using a local testing server and have the SSO stuff turned on, it will be hitting your live site for the SSO check, not the testing server. Probably not a big deal, but something to consider.

3. I cached my template within FoxyCart admin. I didn't get any warnings etc.

4. When I test this, it simply lets me know if the promo code I enter is good or not (in real time). Once I submit my order, the promo code is sent through as additional information and shows on receipt page / shop owner email / customer email.

@RevConcept - if it works for your needs and you've tested that it works, then that's great!

One gotcha with that approach - as I think Lance posted earlier, as the actual code is included in your javascript then it is possible for someone to get the correct code by viewing the source code of the page. If that's not an issue for you, then that's ok.

One more question: is there a way to remove the data passed in fc_custom_fields from the receipt page and the confirmation email the shoppers receive? I only want the info to show for the store owners.

I can't seem to remove the custom fields from the email template. There is a placeholder of ^^receipt^^ spitting out an unordered list with no inline css to designate one list item from the next. Any way around this?

You could also take the approach that you have two fields. One is the visible coupon entry field, and one is a hidden field. If you prepend the visible entry field name with "x:" then it won't be submitted with the order, so that would prevent invalid coupons being submitted. Then in your javascript, if the entry is valid you could copy the value of the visible field to the hidden field - which in turn will be submitted with the order.

That way, only the valid coupon code will be added to the order.

Either way, whether this approach or lance's, you'll need to be able to designate functionality to happen only if the validation fails - is that possible to do? What you've scripted above just blanks out the coupon value on page load, not after a failed entry.

I think this idea from @fc_adam above sounds ideal. Again, not exactly sure how to write the script for it though:

You could also take the approach that you have two fields. One is the visible coupon entry field, and one is a hidden field. If you prepend the visible entry field name with "x:" then it won't be submitted with the order, so that would prevent invalid coupons being submitted. Then in your javascript, if the entry is valid you could copy the value of the visible field to the hidden field - which in turn will be submitted with the order.

If the third-party JS you're using supports a success function, you could just invoke that code in the success function. If it does not have a success function, you will either need to add this to the third-party script or you will need to have a way to determine whether or not the code was valid and then invoke this script on success.

If you're only including livevalidation for this purpose only, and considering it doesn't have callback functionality - your best bet might be to just run your own little validation script. Based on the manual coupon entry script on our snippets section of the wiki, I've pulled the following together: http://pastie.org/private/avra1slam5hmx8p73evbq

Note that no name is given for the visible coupon entry field - this will prevent it submitting with the form. I've also set some very basic obfuscation to the coupon code that the customer needs to enter, so it's not as simple as someone viewing the source of the page to get the code. To create the obsfucated code, you simply go to this page and apply the ROT13 algorithm and paste the result into the FCtoken variable. Note that customers don't add the obsfucated code - but they type it in normally and the code will validate it for you. For example, if the code was "MyCode" this would become "ZlPbqr" - but your customers would have to enter "MyCode" to validate.