I found what I think is the solution but so far haven’t been able to get it to grab the email address from an ACF options field with the below:
/**
* Register the Smart Tag so it will be available to select in the form builder.
*
* @link https://wpforms.com/developers/how-to-create-a-custom-smart-tag/
*
*/
function wpf_dev_register_smarttag( $tags ) {
// Key is the tag, item is the tag name.
$tags['xorganisers_email'] = 'Organisers Email';
return $tags;
}
add_filter( 'wpforms_smart_tags', 'wpf_dev_register_smarttag' );
/**
* Process the Smart Tag.
*
* https://wpforms.com/developers/how-to-create-a-custom-smart-tag/
*
*/
function wpf_dev_process_smarttag( $content, $tag ) {
// Only run if it is our desired tag.
if ( 'xorganisers_email' === $tag ) {
$theemailx = get_field('organisers_email', 'option');
// Replace the tag with our link.
$content = str_replace( '{xorganisers_email}', $theemailx, $content );
}
return $content;
}
add_filter( 'wpforms_smart_tag_process', 'wpf_dev_process_smarttag', 10, 2 );
The above option appears in WPForms as a smart tag but it’s not grabbing the email address from the field.
Any ideas what I could be doing wrong?
-
This reply was modified 4 years, 2 months ago by
one3rdnerd.
I solved it. I must have changed my field name.
The above works for anyone else who wants to do this.
Just change your field name from organisers_email to whatever you create in ACF.
Hi @one3rdnerd,
We’re glad to hear you’ve got that sorted and thanks for the update! If you’d like more help with using WPForms Lite, please feel free to reach out.
Thanks 🙂