When you create a new download with Easy Digital Downloads, a purchase button is automatically appended to the bottom of your single download pages. What if you’d like to modify this button to add new CSS classes, or remove the price?
There’s an option on each download’s edit/publish screen to “Disable the automatic output of the purchase button”, which would allow you to use the [[purchase_link]] shortcode instead (giving you access to all the parameters), but there’s another way if you don’t mind doing it through code.
First we need to unhook/remove the default function that outputs the button, make a copy of the function, and then re-hook/add our function into the same location. The default location this button as mentioned above is at the bottom of the download pages, which uses the edd_after_download_content hook.
Copy and paste the code below (mind the opening PHP tag) into your child theme’s functions.php or custom plugin and adjust as necessary.
This example show you how to add a new CSS class called my-new-class, and turns the purchase button’s price off:
The edd_get_purchase_link function you see above accepts all of the same arguments as the [[purchase_link]] shortcode. This is because the shortcode actually uses the exact same function.
You can also go one step further and modify the button on a per download level. The example below uses a simple PHP switch statement, checking for each download ID: