impress-org / givewp

GiveWP - The #1 Donation Plugin for WordPress. Easily accept donations and fundraise using your WordPress website.
https://givewp.com/
GNU General Public License v3.0
340 stars 191 forks source link

Add filters or more actions to receipt shortcode template #4647

Closed Jany-M closed 2 years ago

Jany-M commented 4 years ago

We need to customize the receipt content in various parts. Some parts are purely html/classes, others are the items' values (eg. Donation Title) or extracting specific data from the donation ID or user. Also, not everybody might want to use a table, so that too should be wrapper in an action that's easily replaceable with some other html wrapper (opening and closing).

Currently we replace the whole shortcode-receipt.php Give template file, with a custom one, to achieve this, but it's not well maintainable in the long run.

Please consider wrapping the page content in actions instead of hardcoding it in the page, so that we can remove/add exactly where necessary, custom code... and/or provide filters.

<?php
    do_action( 'give_payment_receipt_before', $donation, $give_receipt_args );

       // This foreach is hard-coded, but it should be an action or there should be a specific filter to be able to manipulate/customize the data better

        foreach ( $give_receipt_args['donation_receipt'] as $receipt_item ) { ?>
        <?php if ( filter_var( $receipt_item['display'], FILTER_VALIDATE_BOOLEAN ) ) : ?>
            <tr>
                <td scope="row"><strong><?php echo $receipt_item['name']; ?></strong></td>
                <td><?php echo $receipt_item['value']; ?></td>
            </tr>
        <?php endif; ?>
    <?php } 

       action( 'give_payment_receipt_after', $donation, $give_receipt_args );
?>
jonwaldstein commented 2 years ago

@Jany-M what specific customizations are you looking to achieve? We do currently have the give_donation_receipt_args filter and those before/after actions. Although, it sounds like you're looking to go further than what those will allow.

Jany-M commented 2 years ago

@jonwaldstein In general (in core and add-ons), there's too much packed in whole functions. Eg. Form names, text that may go before or after it, or before/after the total, after the total, should be wrapped in something that we can easily manipulate, like WooCommerce does (they literally wrap everything, text, buttons, even their opening/closing divs, in hooks/filters we can change easily without affecting the core of their functions). By having whole chunks of code in single functions, requires us to customize the whole thing and lose over time compatibility.

jonwaldstein commented 2 years ago

@Jany-M I agree, a lot of what your describing we refer to as the legacy codebase. The receipt snippet above dates back to 2014-2016 - a lot has happened since then lol and we are constantly improving stability & performance while balancing new features, customizability, and bugs. So in short, I feel your pain 😄 .

When we analyze requests like this, it's very easy to go down a rabbit hole, cleaning up old code. When it comes to introducing new filters & actions we have to be very careful because they become a public api that anyone can manipulate but are often hard to maintain in the long term.

Since this is technically a feature request I would suggest you add this suggestion to our feedback/feature tool https://givewp.canny.io/ where other folks can upvote & contribute ideas. As you can imagine, we get a lot of requests. So, every 6 weeks we compile our feedback list on canny to decide what to work on outside of our main development cycle.

Hope this was remotely helpful. We appreciate your ideas and patience 🙌

Jany-M commented 2 years ago

@jonwaldstein I understand of course. Over the past 3-4 years I've been in touch with Ben and Mat very often (usually because of rare bugs or missing documentation) and we've managed to solve pretty much everything that's come up. Regarding this, I'm sure it's not a priority, just don't forget that a plugin that developers love to work with and is easily customizable (code-wise mostly, backend-wise I think you guys have already improved it greatly over the past 2 years, for the common user), is a plugin that is preferred among others (and pushed to clients) ;)

JoshuaHungDinh commented 2 years ago

Suggested as a feature request.