Skip to content

Instantly share code, notes, and snippets.

@mintplugins
Created January 27, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mintplugins/d60097919e62b39a54fb to your computer and use it in GitHub Desktop.
Save mintplugins/d60097919e62b39a54fb to your computer and use it in GitHub Desktop.
/**
* Convert buy buttons to straight-up download buttons if the download is free
*
* @since 1.0.0
* @link http://mintplugins.com/doc/
* @see function_name()
* @param array $args See link for description.
* @return void
*/
function mp_edd_free_edd_purchase_download_form( $purchase_form, $args ){
//Get price
$price = get_post_meta( $args['download_id'], 'edd_price', true );
//If the price is greater than 0
if ( $price > 0 ){
//Return the normal button
return $purchase_form;
}
//If the price is 0
else{
//Get deliverable file
$deliverable_file = get_post_meta( $args['download_id'], 'edd_download_files', true );
//return a button that links to the deliverable in a new window
return '<a class="button edd-free-download-btn" target="_blank" href="' . $deliverable_file[0]['file'] . '">' . __( 'Download', 'edd_free_downloads' ) . '</a>';
}
}
add_filter( 'edd_purchase_download_form', 'mp_edd_free_edd_purchase_download_form', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment