Custom PayPal Donate Button, WordPress

Add this code to your functions.php or snippet plugin.

This code finds buttons that has “.donate” class and when those buttons clicked opens the Paypal donate page.

Change the email and name fields according to your needs.

function custom_donate_button_script() {
    document.addEventListener('DOMContentLoaded', function() {
        // Find all the buttons with the class '.donate' in the document
        var donateButtons = document.querySelectorAll('.donate');

        // Iterate over each donate button
        donateButtons.forEach(function(button) {
            // Add click event listener to each donate button
            button.addEventListener('click', function() {
                // Create a new form element
                var form = document.createElement('form');
                form.action = '';
                form.method = 'post';
       = '_top';

                // Add the necessary input fields to the form
                form.innerHTML = `
                    <input type="hidden" name="business" value="">
                    <input type="hidden" name="no_recurring" value="0">
                    <input type="hidden" name="item_name" value="STELP e. V.">
                    <input type="hidden" name="item_number" value="STELP Donation">
                    <input type="hidden" name="currency_code" value="EUR">
                    <img alt="" width="1" height="1" src="">

                // Append the form to the document body

                // Submit the form

                // Optionally, remove the form after submission
add_action('wp_footer', 'custom_donate_button_script');

Leave the first comment