Jump to content

discount code


grucker

Recommended Posts

You'll need a new mysql table to keep the codes in, as well as their associated values (such as, for example, -$3.00, -10% ...etc)

 

You'll need to randomly generate a code ID (5 - 10 chars) and insert it into the db along with it's value.

 

Then it's pretty much simple math.

 

Allow the user a place to input the code, search the mysql database for that code, figure out what variable is used for their current total (before postage as you said) and then call the shopping carts checkout page again, using the new value as the subtotal.

 

You can even do fun things like if you want it to be a one time use only coupon, simply add another field such as "status" and update that to equal 1 if they use it, rather than 0 if it hasn't been used yet.

Link to comment
Share on other sites

Include the field in the form, then while validating the rest of the form, check if the discount code field has a value, and if it does, validate the value. If the value is valid, apply the discount and calculate the new subtotal, otherwise, if the value is invalid, handle it like any other validation error. This is in no way exact, but should give you an idea of the logic you'll need to use.

 

if( isset($_POST['discount_code']) ) {
     // query the database, or check against an array of valid codes and get the discount percentage
     if( /*code_is_valid */ ) {
          $new_subtotal = // calculate new subtotal
     } else {
     // set an error, as code is not valid
}

Link to comment
Share on other sites

Thanks for the promp replies I only want to put a a simple code ie. discount or member.

If I press the buy now button it goes to PAYPAL I have included the function files involved for a more detailed look. Thanks again

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.