Bypass Checkout For Free WP Repository Plugins in Easy Digital Downloads

This is for you if you have an Easy Digital Downloads store, and you also have some free plugins in the WordPress plugin repository. In your Easy Digital Downloads store, you may want to offer direct downloads of your free plugins from the WordPress plugin repository.

You may want to show your free WordPress plugins in your Easy Digital Downloads store, and allow customers to download them by bypassing the EDD checkout, and downloading directly from the WP plugin repository.

The following code will replace the Purchase or Add to Cart buttons for any products in your EDD store that are available for free in the WP plugin repository. The Purchase or Add to Cart buttons will be replaced with a “Download” button. The customer will be able to stay on the same page in your EDD store, while downloading the plugin from the WP repository.

This allows your customer to bypass checkout. It allows you to display your free WordPress plugins in your EDD store. And, you will not have to maintain an extra ZIP file of your plugin on your site, so you can just offer the latest release available at WordPress.

The code goes into your functions.

PHP

/**
 * Modify the purchase link for downloads that are available on
 * the WP repo to allow direct download bypassing checkout.
 */
add_filter('edd_purchase_download_form', 'isa_edd_purchase_form', 20, 2);
function isa_edd_purchase_form( $purchase_form, $args ) {
	$download_id = absint($args['download_id']);
	if ( $download_id ) {

		// If this plugin exists on the wordpress.org repo, get its latest download link URL
		$download = edd_get_download( $download_id );
		$download_url = isa_latest_plugin_tag_download_url( $download->post_name );

		// If link exists, show the Download button
		if ( ! empty( $download_url ) ) {

			// build download link
			ob_start();
			?><a href="<?php echo esc_url($download_url); ?>" class="free-download-button"><span>Download</span></a><?php
			$purchase_form = ob_get_clean();
		}

	}

	return $purchase_form;
}

Mandatory Step

You will also need to add the isa_latest_plugin_tag_download_url function from this page because that function is used here.

In addition, you will want to add CSS styles to style the link if you want to make it look like a button rather than simply a link. For example:

CSS

.free-download-button {
	color: #fff;
	background: #428bca;
	font-weight: bold;
	padding: 15px;
	display: inline-block;
	margin-top: 10px;
	width: auto;
	box-shadow: 2px 2px 5px 0 rgba(136,136,136,0.6);
	text-decoration: none;
}

Or, instead of adding custom CSS, if your theme already has a nice button style, you could replace free-download-button with your theme’s button style selector in line 19 of the PHP code block, above.

For offering free downloads in your EDD shop, you may also want to see Remove Agree To Terms For Free Downloads and Remove Credit Card icons on Checkout Page.

See more:

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]