WP e-Commerce, how to process $0.00 sales and 100% coupons which PayPal will not accept

The Problem

I had a question recently about why a coupon was not being processed at the PayPal end. It turns out that PayPal will not process a $0.00 sale. If you have an item for $10.00 and a discount coupon for $10.00 the coupon is processed on the WP e-Commerce checkout page showing a total of $0.00, but when the user gets to PayPal the coupon is totally ignored and the price is $10.00. Not good!
If you reduce that coupon to $9.99 the sale would go through with a total of $0.01. That is not a very elegant solution. Many sites now have partnerships with coupon sale sites, these third party sites sell coupons which the user then expects to use to purchase at no cost. Some people have tried using the Test Gateway but this is only going to work if all of your sales are $0.00. You still want to send customers who have a cash balance to pay on to PayPal when they click Purchase.


Thanks to getShopped user dhtbrowne who supplied this solution http://getshopped.org/forums/topic/how-to-stop-free-products-redirecting-to-gateway/#post-268526

I will reproduce his code just as he wrote it and add a little explanation as things can be hard to find on the getShopped forums and even have a habit of disappearing completely. I have tested this with Storefront Themes, Elegance theme version 1.4.5, WordPress 3.3.1 and WP e-Commerce It should work for most themes and hopefully newer WP e-Commerce versions. Please leave a comment if you test it in higher WP e-Commerce versions.
The following solution will intercept any $0 purchase and the “wpsc_purchlog_edit_status()” changes the order status to payment accepted, sends out all the necessary emails and deactivates coupons if they are set to use once.

First you need to make a page that says thank you, for users to be redirected to after they click purchase. Get the Page ID of the thank you page. To do this open it in WordPress for editing and look in the URL bar of your browser you will see a URL ending in something like this.
You need that number, in my case 492, it is the ID of the thank you page.

Here you need to edit a PHP file it is very easy, just pasting in some code, so you can avoid the whole code editor thing if you want and do this in WordPress. Go to Appearance/Editor, find functions.php on the file list and open it. Right BEFORE the very last ?> paste this code and change the 492 to the ID of your thank you page. When done make sure you have no blank space or lines after that final ?>

add_action('wpsc_submit_checkout', 'free_coupon_test');
function free_coupon_test($order_info) {
global $wpdb;
$purchaseID = $order_info['purchase_log_id'];
$rows = $wpdb->get_results("SELECT discount_data, totalprice FROM " . $wpdb->prefix . "wpsc_purchase_logs WHERE id=$purchaseID LIMIT 1");
if ($rows[0]->totalprice == 0 && !$rows[0]->discount_data == '') {
wpsc_purchlog_edit_status($purchaseID, '3');
header("Location: " . get_permalink(492));

Remember change the 492 to your thank you pages ID!

Thats it, if you have done it right any $0 purchase should redirect to your thank you page. You should receive a purchase log and the customer receives a thank you receipt. To check it, try buying something yourself for $0 so that you get both emails.


  1. Drider
    December 14, 2015

    Hi Michael,The latest vrioesn (1.3.5) that was just released did not solve the problem. The previous vrioesn was removed and the new vrioesn was installed. The only thing that appears at the top of the Add Order page are the words Add New Order .Tried deactivating other plug-ins. The purchased plug-in does not work. Do you know when a solution/fix will be available? Do you know of any specific other’ plug-ins that might cause a problem with the manual order plug-in? It is a little disheartening to purchase an expensive plug-in that doesn’t work.Sincerely in great need of a solution .A fix would be very much appreciated. Thank you.

  2. Nadine
    December 27, 2012

    Getting an error on

    if ($rows[0]->totalprice == 0 && !$rows[0]->discount_data == ”) {

  3. Greg
    November 20, 2012

    Awesome! Thank you very much! I’ve been trying all day to get it to work !!

  4. Chris
    October 2, 2012

    This is great if you just want to have a $0 order. But what if you want to have shipping paid through PayPal. How would one force the order to always be at least $0.01?

  5. Merras
    September 16, 2012

    Oh, man you made me sooo happy!

    This feature should be a core feature in WP EC; however you made a working solution. Cheers, and many thanks!

  6. Alex
    July 31, 2012

    Thanks! This is great… now I just have to figure out how to make payment info fields not required…

    • mgason
      August 8, 2012

      Not quite sure what you mean by ‘payment info fileds not required’? On Settings/Store/Checkout tab you can set fields to not required.


Leave a Reply