(303) 819-3968

Digital Download Shortcode for PHPurchase

1st let me say PHPurchase is my favorite shopping cart plugin for WordPress. When implementing a custom cart in WordPress there’s nothing like the flexibility and ease of integration that PHPurchase offers. One thing I found that was missing is a shortcode that will create the download link for a purchased product. I spent a few hours last night and created the shortcode for digital download links.

Requirments:

Step 1:

Download the code unzip the files and upload them to wp-content/plugins/phpurchase/pro.

Step 2:

Open wp-content/plugins/phpurchase/pro/hook.php to edit.

Step 3:

At the end of the file add this code just before php is closed(?>).

function phpurchaseDownloadLink($attrs, $content='null') {
global $wpdb;
$order_items = PHPurchaseCommon::getTableName('order_items');
$recurring_items = PHPurchaseCommon::getTableName('recurring_items');
$phproducts = PHPurchaseCommon::getTableName('products');
$mylink = $wpdb->get_results("SELECT a.*,c.download_path FROM ".$order_items." AS a, ".$recurring_items." AS b, ".$phproducts." as c WHERE b.account_id= '".$_SESSION['PHPurchaseMember']."' AND a.id = b.order_item_id AND a.product_id = c.id", ARRAY_A);
$attrs['mylink'] = $mylink;
$view = PHPurchaseCommon::getView('pro/digital-download.php', $attrs);
return $view;
}
add_shortcode('digital-download', 'phpurchaseDownloadLink');

function phpurchaseDownloader() {
$view = PHPurchaseCommon::getView('pro/digital-downloader.php');
return $view;
}
add_shortcode('digital-downloader', 'phpurchaseDownloader');

Step 4:

Login to WordPress. Once logged in create a new page named “Purchased Downloads”(you can rename it after publishing just don’t change the link). Add [digital-downloader] to the content on the page and nothing else.

Step 5:

Now you can add [digital-download item-number=""] to any page or post with this shortcode. If you add an item number(s) it will check to see if the current customer has purchased that product. If the user has purchased the product then it will show the link if they have not the link will be blank. If they have purchased the product, but there in no download for the product it will return a message, “No download currently available”.

If you want to display all downloads purchased by a user simply leave item-number blank. If you want to show more than one specific download at a time you can use a comma separated list([item-number="1,2,3"].

To Change the way items are displayed check out the digital-download.php file. You will see a couple loops that format the links.

Peak Studios at Google+