Hello,
Thanks for the donation, that’s very kind ??
There are several problems with your code:
1. You make a condition on a variable that isn’t set if($my_field === 'no')
. $my_field
isn’t set at this time.
2. Your code $my_post_field = get_field('order_plan', $post_id);
retrieve the data from the current page that display the form. I don’t think that’s what you’re looking for. If you want to retrieve actual form user input just use: $my_post_field = get_field('order_plan');
(without the $post_id
). You’ll find code example in the “Advanced tab”.
3. Your e-mail headers look wrong, as you’ve set the “From $email”, but $email = array('email');
which doesn’t make sense.
In order to debug your code, I would advise you to code and test step by step.
Here is an example:
add_action('acfe/form/submit/request-map-info', 'my_form_custom_action', 10, 2);
function my_form_custom_action($form, $post_id){
// Retrieve "order plan" user input
$order_plan = get_field('order_plan');
if($order_plan === 'yes'){
echo 'yes';
die;
}elseif($order_plan === 'no'){
echo 'no';
die;
}
}
Note that I added die;
after writing a debug message, to stop all other execution. This is basically a code to test your condition first. You can also use acf_log('yes')
to log data in the debug.log
file instead of writing a text.
Once your condition work as expected, you can go ahead and write + debug your wp_mail()
call. Again, starts by writing a custom wp_mail()
function, without variable. Then once the mail is sent, set your variables etc…
Hope it helps!
Regards.