Feature: add receipt api for fields #7149
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves: GIVE-180
Description
Preface
For fields that either don't store their value in meta (or at all), use a custom scope, or the field attributes just does not correlate to what should be displayed on the confirmation page - there is currently no way to modify the label & value.
At first I was going to simply add an action like
givewp_donation_confirmation_receipt
(which we still can) but then realized how removed from context the action is as it relates to field data. For example, you will often need to go through the form schema to find the field to use field attributes/settings. Where as giving fields a first-class api has the benefit of staying in context with the rest of the field settings/schema and likely will reduce logic & overhead.The solution
This gives fields a way to optionally & programmatically display their label/value in the confirmation page. Currently the
receiptValue(Closure $value)
api is a simple closure that (in the context of a donation form) will pass the$field
and$donation
model. I thought about adding a string option like scopes do but thought this would be the simpler way to go for now (since I also added filters).For example:
I also added a couple filters so folks could modify the values if need be:
apply_filters('givewp_donation_confirmation_page_field_value_for_{$fieldName}', $value, $field, $donation)
apply_filters('givewp_donation_confirmation_page_field_label_for_{$fieldName}', $value, $field, $donation)
These would be most useful for customers using add-ons that add their own receipt labels/values and might want to modify that (maybe for language, syntax, or something else). You could also use these filters instead of the fields api if need be - either way it's an easy win.
Affects
Visuals
Api in action! ("Fund")
Testing Instructions
Or with filters:
Pre-review Checklist
@unreleased
tags included in DocBlocks