While I am working on a wordpress website
I am using advanced custom fields acf by wp engine and wpf fluent forms
I have created a custom post name service and created a field group for the service post type I have a lot of services on my website each service has different payments charges now I want that when user click any service I have created a single post template where the single service design is ready and in that template the wp fluentforms form is emended
No I want to show the price which was created in the scf field group to show that price into the form for further calculations that when a user click on the post the displayed form should fetch the price field from the ecf and show into the field can anyone guide me how can I do this?
I have tried a piece of code but the value is not visible into the form the code is below
the code is below
function populate_acf_field_in_fluent_form($form_data, $form) {
// Replace ‘your_form_id’ with the ID of the specific Fluent Form you want to target
if ($form->id == ’11’ && is_single() && get_post_type() == ‘service’) {
$post_id = get_the_ID();
$price = get_field(‘service_price’, $post_id); // Replace ‘price_field_name’ with your ACF field name
// Loop through form fields to find the numeric field and set its value
foreach ($form_data['fields'] as &$field) {
if ($field['name'] == 'service_price') { // Replace 'your_numeric_field_name' with your Fluent Forms field name
$field['value'] = $price;
break;
}
}
}
return $form_data;
}
add_filter(‘fluentform_rendering_form_data’, ‘populate_acf_field_in_fluent_form’, 10, 2);
Mahar Muhammad Zahid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.