Custom Fields Data
-
Hi,
I’ve added 2 custom fields to my donation forms following the documentation using the mothers name example.
It appears to be functioning when submitting the info but I don’t see where the information is visible in the back end. Is there additional code that I need to add to view it on the backend?
https://givewp.com/documentation/developers/how-to-create-custom-form-fields/
-
Hi @smdstudios,
You can use this function to display the field data in the donation details page:
function render_givewp_field_api_fields( $payment_id ) { $field_name = give_get_meta( $payment_id, 'guestName', true ); if ( $field_name ) : ?> <div id="<?php echo wpautop( $field_name ); ?>" class="postbox"> <!--Replace 'Field Label' with a relevant label. --> <h3 class="handle"><?php esc_html_e( 'Field label', 'give' ); ?></h3> <div class="inside" style="padding-bottom:10px;"> <?php echo wpautop( $field_name ); ?> </div> </div> <?php endif; } add_action( 'give_view_donation_details_billing_after', 'render_givewp_field_api_fields', 10, 1 );Hope it helps!
Thank you.
Just to clarify I can drop the code into my functions file, edit and that is all the code I need?
Your code didn’t do anything for me so I want to ensure I’m not missing something.
Same goes for the custom fields I added to my donations page?
Hi, @smdstudios.
Yes, that’s what you’d need to do. If you need assistance implementing custom PHP code on your website we have this guide:
https://givewp.com/documentation/resources/adding-custom-functions-to-your-wordpress-website/
Please note that this code snippet is provided as an example of how you can extend GiveWP with code. It’s up to you to implement and customize to your liking. We cannot provide support for custom code on your website, only the code that we create and distribute.
It’s important that you edit the code though to reflect the custom fields you created.
Thanks for using GiveWP! Have a great day.
Thank you..I just wanted to make sure that I didn’t need to write any additional code actually to save it to the DB.
If I can’t get that display function to work, I can manually pull the custom fields from the DB.
Try something like this:
function render_givewp_field_api_fields( $payment_id ) { $occupation = give_get_meta( $payment_id, 'occupation', true ); $employer = give_get_meta( $payment_id, 'occupation', true ); if ( $occupation ) : ?> <div id="<?php echo wpautop( $occupation ); ?>" class="postbox"> <!--Replace 'Field Label' with a relevant label. --> <h3 class="handle"><?php esc_html_e( 'Occupation', 'give' ); ?></h3> <div class="inside" style="padding-bottom:10px;"> <?php echo wpautop( $occupation ); ?> </div> </div> <?php endif; } if ( $employer ) : ?> <div id="<?php echo wpautop( $employer ); ?>" class="postbox"> <!--Replace 'Field Label' with a relevant label. --> <h3 class="handle"><?php esc_html_e( 'Employer', 'give' ); ?></h3> <div class="inside" style="padding-bottom:10px;"> <?php echo wpautop( $employer ); ?> </div> </div> <?php endif; } add_action( 'give_view_donation_details_billing_after', 'render_givewp_field_api_fields', 10, 1 );-
This reply was modified 3 years, 8 months ago by
natecovington.
-
This reply was modified 3 years, 8 months ago by
natecovington.
Hi, @smdstudios.
Do you still need assistance here? Looking forward to helping you get to the bottom of this!
I still haven’t been able to get the data to appear in the admin section.
I might just skip that and try and just get the extra fields in a data export. Is there any additional code needed for that?
Hi @smdstudios,
I made a quick and dirty video tutorial here that shows you how to add the custom field data to the donation details page and to the export: https://somup.com/c3jT04Ujl9
Here’s the code I used there:
https://gist.github.com/rickalday/ac01194ea0a930b5816f41754fa5a148If you use the Code Snippets plugin as I did, you don’t need the opening
<?phptag in the code.Hope it helps!
Thank you! That helped a lot!!
Glad to hear that, @smdstudios. @mrdaro is a gem!
We’re looking to earn more 5-star reviews on our WordPress.org page. If you’ve found our support helpful and if you’ve been loving the GiveWP plugin, I’d love to earn a 5-star review from you!
WordPress: https://wordpress.org/support/view/plugin-reviews/giveReviews help other organizations see how much value and success other GiveWP users get from our products. I truly appreciate your time! (and you’d totally make my day 😊).
Thanks for using GiveWP! Have a great day.
-
This reply was modified 3 years, 8 months ago by
The topic ‘Custom Fields Data’ is closed to new replies.