• Resolved trashcashph

    (@trashcashph)


    I hope this message finds you well. I have a question regarding the customization of WPGive donation forms. I would like to add a text element to the form that dynamically computes the equivalent offset of the donation amount selected by the customer.

    Here’s what I’m trying to achieve: When a customer selects a specific donation amount, let’s say $10, I want the text element to be updated to display “Your estimated impact is 10 KG.” Similarly, if they choose $20, the text should update to “Your estimated impact 20 KG.”

    Could you please guide me on how to correctly implement this functionality? Any suggestions or code examples would be greatly appreciated.

    Thank you in advance for your assistance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Matheus Martins

    (@matheusfd)

    Hi, @trashcashph.

    Glad you reached out.

    You can find a similar setting for this by navigating to Donations > Settings > All Forms and then selecting “edit” under the Multi-Step form you’d like to update. Click the left-hand menu option titled “Donation Options”, and scroll down just a bit to see the Donation Levels. This is where you can add text:

    Screenshot-2023-05-02-at-2-06-32-PM.png

    In the Multi-Step and Classic templates, the text you enter will display as a tooltip, it won’t replace the numerical value. It’ll look something like this:

    Screenshot-2023-05-02-at-2-09-21-PM.png

    We are collecting feedback about the possibility of adding text to donation levels. I’ve added you as a voter for it here https://feedback.givewp.com/feature-requests/p/donation-levels-should-support-textdescriptionsmulti-step-classic-form.

    ?We are actively tracking user feedback to understand further the needs you all have. You can use the link to check in for updates or to provide additional details of your own. I would encourage you to comment on that post about the impact this would have on your organization. Information like that is always helpful for our teams to see.

    I’ve also linked your ticket internally, so if this feature request is developed, we can reach back out to update you.Give the post above a look, and let me know if there are any additional details you would like for me to add. I want to ensure your need is as accurately reflected as possible, and I’m happy to include an internal note to our teams with any specific information you would like them to have.

    Thanks for using GiveWP! Have a great day.

    Thread Starter trashcashph

    (@trashcashph)

    Hi @matheusfd Thank you for replying to my inquiry! Is there’s a way to modify the code to add text above donation options to display the description after customer tap each options?

    Plugin Support Matheus Martins

    (@matheusfd)

    Hi, @trashcashph.

    It would be possible with some custom code, but I do not have a handy code snippet I could give you. In this case, you would need to develop it.

    ?Please let us know if you have further questions or need additional assistance!

    Thread Starter trashcashph

    (@trashcashph)

    Hi

    I have already done what I want to achieve. I created a new custom function and I access the CSS class from there. Here’s my sample JS code.

    // Get the selected donation amount and update the impact text
    
    function updateImpactText() {
    
        var selectedAmount = document.querySelector('#give-amount').value;
    
        selectedAmount = selectedAmount.replace(/,/g, '');
    
        var impactValue = selectedAmount / 55;
    
        var weightEquivalent = Math.round(impactValue * 100) / 100;
    
        var bottleEquivalent = (impactValue * 55).toLocaleString();
    
        document.querySelector('#selected-value').textContent = selectedAmount;
    
        document.querySelector('#weight-equivalent').textContent = weightEquivalent;
    
        document.querySelector('#bottle-equivalent').textContent = bottleEquivalent;
    
    }
    
    window.addEventListener('load',populateImpact);
    
    // Add the input event listener to update the impact text whenever the value changes
    
    document.querySelector('#give-amount').addEventListener('input', updateImpactText);
    
    // give-donation-level-btn give-btn give-btn-level-0 give-default-level
    
    var donationButtons = document.querySelectorAll('.give-donation-level-btn');
    
    for (var i = 0; i < donationButtons.length; i++) {
    
        var button = donationButtons[i];
    
        // Exclude the "Custom Amount" button
    
        if (!button.classList.contains('give-btn-level-custom')) {
    
        button.addEventListener('click', handleButtonClick);
    
        }
    
    }
    
      // Event handler for button click
    
    function handleButtonClick(event) {
    
        // Get the selected donation amount from the clicked button
    
        var selectedAmount = event.target.value;
    
        selectedAmount = selectedAmount.replace(/,/g, '');
    
        // Update the impact text with the selected amount
    
        var impactValue = selectedAmount / 55;
    
        var weightEquivalent = Math.round(impactValue * 100) / 100;
    
        var bottleEquivalent = (impactValue * 55).toLocaleString();
    
        document.querySelector('#selected-value').textContent = selectedAmount;
    
        document.querySelector('#weight-equivalent').textContent = weightEquivalent;
    
        document.querySelector('#bottle-equivalent').textContent = bottleEquivalent;
    
    }
    
    function populateImpact(){
    
        document.querySelector('#selected-value').textContent = "0";
    
        document.querySelector('#weight-equivalent').textContent = '0';
    
        document.querySelector('#bottle-equivalent').textContent = '0';
    
    }
    
    


    Plugin Support Matheus Martins

    (@matheusfd)

    Glad to hear that you found a workaround, @trashcashph.

    Thanks for using GiveWP! Have a great day.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding dynamic text to WPGive donation form’ is closed to new replies.