Home › Forums › General Issues › How to show the fields of AСF in email?
Can you help with this issue?
https://stackoverflow.com/questions/51961628/how-to-show-the-fields-of-a%D0%A1f-in-email
Thanks!
I think the problem is your use of single quotes where there should be double quotes:
get_field( 'user_phone', 'user_{$user_id}' )
Should be
get_field( 'user_phone', "user_{$user_id}" )
I’ve left an answer on your post.
Thanks for the answer.
I did as you said. Unfortunately, these fields are still not shown in the email.
Can you verify it’s being saved in the database as in the usermeta table?
Yes, the data of these custom fields are saved in the database.
I copy and pasted the code supplied in your Stack Overflow question, changed the single quotes to double quotes, changed the ‘to’ email, and saved the code as a custom 1 file plugin. It worked as expected, I received the user field in the email sent.
If you’re not getting it in your email then there’s something not provided that we’re missing or the data isn’t saved into the usermeta table.
I understood. Do you use the ACF for WooCommerce plugin? This can be a problem with the ACF for WooCommerce plugin?
I need to show custom fields in the WooCommerce account and send user data by email.
If not use the “ACF for WooCommerce” plugin, then how do put custom fields in my account page of WooCommerce?
As it turned out, this plugin “ACF for Woocommerce” saves the field data as meta_key: “field_5b7e4f388fd11” and meta_value: “+79998006655”. Tell me how to correctly display the fields in my code?
get_field( 'field_5b7e4f388fd11', "user_{$user_id}" )
This for some reason does not work. Emails come empty fields ((
Have you tried using get_user_meta directly?
get_user_meta($user_id, 'field_5b7e4f388fd11', $single=true);
Maybe that will work around the weirdness.
Here is the documentation for get_user_meta().
Thanks for the answer. This option works, but if you replace the existing field value, for example “+79998006655” with the new “+78009995566”, then everything is stored correctly in the database, and the old version of “+79998006655” comes to the administrator’s email.
If the custom field is a checkbox, then it is correctly stored in the database, but only “Array” is shown in the administrator email.
How can this be remedied?
Does the NEXT email after that show the updated previous data?
e.g.
Attempt #1:
Original DB value: 123
Updated value: 567
Email sends: 123
Attempt #2
Original DB value: 567
Updated value: 999
Email sends: 567
I’ve looked into it again and wp_user_meta()
is just a wrapper for get_metadata()
which caches its results.
I suspect you have made your user edits earlier in the exection of the request, then later in the execution you want to send this email.
You can bust the cache by putting this at the top of your email call:
update_meta_cache( 'user', $user_id );
Please accept my answer on SO too 🙂
Thanks for the answer. I answered SO. Tell me how to put update_meta_cache ('user', $ user_id);
? Can you show this in my code example?
And what about checkboxes? Everything is correct in the database, and in the email to the administrator shows “array” (
The topic ‘How to show the fields of AСF in email?’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.