Enable Free Downloads in WordPress E-Commerce

For anyone who uses WordPress E-Commerce from www.getshopped.org, one of the top free e-commerce solutions for WordPress installations, enabling free downloads that work well and don’t confuse your customers is tricky out of the box. WordPress E-Commerce insists on passing you though a payment processor (like PayPal, for example) even when the total for your order is $0.00. This can completely baffle your customer in to thinking they are about to make a payment for a free product, and possibly lose you that opportunity to provide that customer with paid services or goods down the road. However, with a bit of code work, you can get around this issue and have your WPEC installation skip the payment processor stage for future free downloads / purchases you might put on your website.

Using e-commerce to allow free downloads might seem strange, but why give away free downloads in the first place? Here’s why: free downloads and giveaways are awesome publicity and help you establish other key marketing tools, like mailing lists, customer bases, and more. Free downloads could be very important to your small business or company in the future, so let me show you how to make enabling free downloads in WordPress E-Commerce better.

Here’s How Enabling Free Downloads in WordPress E-Commerce is Done:

Step 1 – Find the following line of code inside the wpsc-shopping_cart_page.php file:

//this HTML displays activated payment gateways

Edit the <tr> element directly below this line of code, so that instead of <tr> you have the following:

calculate_total_price() == '0') {echo 'style="display:none"';}?>>

This will hide the payment gateway selection step if the price is equal to $0. Next, we need to mark the transaction as paid, skip the payment process, and then create an authorized transaction ID to complete the order and allow your customers to download their files.

Step 2 – Open your active WordPress themes “functions.php” file and paste in this code:

add_action ('wpsc_submit_checkout', ‘freedownload’);
function freedownload ($purchaseinfo) {
global $wpdb, $wpsc_cart, $wpsc_shipping_modules;
$purchase_log_id = $purchaseinfo['purchase_log_id'];
$purchase_log = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`= ".$purchase_log_id." LIMIT 1",ARRAY_A) ;
if ($purchase_log['totalprice'] == '0.00') {
$sessionid = $purchase_log['sessionid'];
$free = new wpsc_merchant_testmode( $purchase_log_id );
$free->construct_value_array();
$free->set_purchase_processed_by_purchid(3);
$free->go_to_transaction_results($sessionid);
}
}

This creates a new function called “freedownload” that bypasses the payment processor step in the check out process, and then generates a unique transaction ID, just like the one you would be returned after a normal transaction, and stores that data. Then, it returns a successful check out page with a receipt and link to start your download.

This configuration is not as simple as a checkbox option in the WPEC administration panel would make it, but if you want to use WordPress and offer free downloads, which is an excellent way to track your items performances, this solution will get the job done for you.

If you liked this post, feel free to share it! I am proud to offer customers in the Greater Toronto Area, including Hamilton, Burlington, Toronto, Oakville and others my WordPress design, development and hosting services at affordable rates. Contact me today for more information and a free quote on your project.

Follow Me on Gumroad

I regularly release free downloads and stock photos, resources and files available for download through my Gumroad page. Enter your email address below to be automatically notified of new releases!