0

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']);
    }
}

1 Answer 1

0

Try using the wpuf_add_post_after_insert hook. This hook gets triggered right after a post is created using WPUF, which means it might be a more appropriate time to save additional data, like the phone number:

add_action('wpuf_add_post_after_insert', 'update_product_acf_field_guest_submission', 10, 3);

function update_product_acf_field_guest_submission($post_id, $form_id, $form_settings) {
    // Check if the form ID matches the specific form where the phone number is submitted
    if ($form_id == '356') {
        // Ensure phone field data exists before using it
        if (isset($_POST['phone_field'])) {
            $phone_number = sanitize_text_field($_POST['phone_field']);
            
            // Update the ACF field for the WooCommerce product
            update_field('acf[field_6512315ee37ae]', $phone_number, $post_id);
        }
    }
}

I've also added an additional check to ensure that the phone_field exists in the POST data before trying to sanitize and save it, just to be safe.

Remember to replace 'acf[field_6512315ee37ae]' with your actual field key if it's different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.