php – How to capture number input from wordpress form into acf field in woocommerce


WUFP Phone fieldI am trying to capture the phone number of guests that submit a form on my woocommerce website using the advancedwoocommerce custom field for phone no custom field plugin. I noticed the phone number they enter doesnt get stored into the woocommerce product phone field made available for them. If there’s a special way to capture it and make sure it stays right in the box please let me know. The guest product frontend woocommerce form was created with wordpress user frontend plugin while the custom field to add the phone no field in woocommerce product data was created with ACF plugin. Then I have made sure the phone field meta and Acf phone meta has same field i.e phone_field.

I have reied below code

// Hook into form submission (replace 'my_form_id' with the actual form ID)
add_action('wpuf_add_post_form_top', 'update_product_acf_field_guest_submission', 10, 3);

function update_product_acf_field_guest_submission($form_id, $form_settings, $post_args) {
    // Check if the form ID matches the specific form where the phone number is submitted
    if ($form_id == '356') {
        // Get the submitted phone number from the form
        $phone_number = sanitize_text_field($_POST['phone_field']);
        // Update the ACF field for the WooCommerce product
        update_field('acf[field_6512315ee37ae]', $phone_number, $post_args['post_id']);

Titus 2 months 2023-09-26T23:35:06-05:00 0 Answers 0 views 0

Leave an answer