"Free" Label and Button for Free Downloads
Shows "Free" instead of 0.00 for free downloads and changes their purchase button to "Download for free", so visitors see at a glance they pay nothing.
Opens WPIDE on
Code
$wpide_edd_free = array(
'price' => 'Free',
'button' => 'Download for free',
);
add_filter( 'edd_download_price_after_html', function ( $formatted, $download_id, $price ) use ( $wpide_edd_free ) {
return ( 0.0 === (float) $price && function_exists( 'edd_has_variable_prices' ) && ! edd_has_variable_prices( $download_id ) ) ? '<span class="edd_price wpide-edd-free">' . esc_html( $wpide_edd_free['price'] ) . '</span>' : $formatted;
}, 10, 3 );
add_filter( 'edd_purchase_link_args', function ( $args ) use ( $wpide_edd_free ) {
if ( ! empty( $args['download_id'] ) && function_exists( 'edd_is_free_download' ) && edd_is_free_download( $args['download_id'] ) ) {
$args['text'] = $wpide_edd_free['button'];
}
return $args;
} );
Notes
Edit the two texts at the top; paid downloads are not affected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.