Support

Account

Home Forums General Issues How to show the fields of AСF in email?

Solving

How to show the fields of AСF in email?

  • 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” (

Viewing 14 posts - 1 through 14 (of 14 total)

The topic ‘How to show the fields of AСF in email?’ is closed to new replies.