Skip Navigation

[Resolved] Passing Name & Email fields from Toolset Form to Woocommerce Checkout Page

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1103687

How can I pass information that a user has just entered in a toolset form to the woocommerce checkout page when the user hits submit? I am using the cred woocommerce feature to send a user directly to the woocommerce checkout page after submitting a form, but I don't know how to pass the info that the user added to the form into the woocommerce form

I've looked for documentation but could not find any.
Can this be solved by passing URL params? If yes, could you give me detailed instructions, I did not understand the ones that were available online

hidden link
click on 'Become a Member'
Fill out form and click on sign up

The woocommerce checkout page follows. Here it would be great to autofill first name, last name and email

Thanks for explaining me how this works.

#1104536

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Toolset Forms Commerce offers the API hook cred_commerce_form_action that will fire just after you submit the form::
=> https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_form_action

Within the callback function, you will have access to anything captured by the form in the global $_POST variable. You can use above hook to build your URL with required URL params.

For example:

yoursite.com/checkout?first=John&last=Smith&email=abc

For example:

add_action('cred_commerce_form_action', 'my_commerce_form_action',10,4);
function my_commerce_form_action( $action, $form_id, $post_id, $form_data ) {
  if ($form_id == 1234)
  {    
    // uncomment next line to inspect the entire post object using server logs.
    // error_log(print_r($_POST, true));
    $first = $_POST['first_name'];
    // ...
    // get the 3 other parameters from the POST object and add them here
    // ...
    wp_redirect( '/checkout?first=' . $first); // add all 4 parameters to the URL string here
    exit();
  }
}

Then in your filter, you should be able to access the URL parameters in the $_GET superglobal:

add_filter( 'woocommerce_checkout_fields' , 'kia_checkout_field_defaults', 20 );
function kia_checkout_field_defaults( $fields ) {
    $first_name = isset($_GET['first']) ? $_GET['first'] : '';
    $fields['billing']['billing_first_name']['placeholder'] = 'First Name';
    $fields['billing']['billing_first_name']['default'] = $first_name;
    return $fields;
}

---- Please feel free to adjust above code as per your need.

More info:
=> https://docs.woocommerce.com/document/checkout-field-editor/

#1104560

Great, thank you very much for this.

Just to be sure I understand correctly: your first example code I can put in a snippet and activate. This will add the url-param ?first=John to the URL whenever a form '1234' is submitted that has the name 'John' in the field called 'first'.

1st question: how would I add additional params in the code?

then your 2nd example code goes also in a snippet and when activated will check the $first_name string and put it as a default value into the 'billing_first_name' field of woocommerce. For that the code uses fields or features of the checkout-field-editor, which has to be installed.

Have I understood this correctly?

more questions:
- so how would the code look for several fields (first name, last name, etc) and where do I find the precide fieldnames of woocommerce so I can flexibly build actions & filters?
- o I have to make any special settings in checkout-field-editor, or will it work right out of the box?
- What exactly does checkout-field-editor do Why is it needed?

Thank you for your help! Tobias

#1104575

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Just to be sure I understand correctly: your first example code I can put in a snippet and activate. This will add the url-param ?first=John to the URL whenever a form '1234' is submitted that has the name 'John' in the field called 'first'.
==> Yes - exactly.

then your 2nd example code goes also in a snippet and when activated will check the $first_name string and put it as a default value into the 'billing_first_name' field of woocommerce. For that the code uses fields or features of the checkout-field-editor, which has to be installed.
=> Well - you can target the fields available on your checkout page and assign the value accordingly.

Have I understood this correctly?
Yes.

more questions:
- so how would the code look for several fields (first name, last name, etc) and where do I find the precide fieldnames of woocommerce so I can flexibly build actions & filters?
=> Well - I this this is a woocommerce question. Could you please be in touch with them.

- I have to make any special settings in checkout-field-editor, or will it work right out of the box?
==> Well, you need to bind your field value to URL param value so that it will display as default value of field.

- What exactly does checkout-field-editor do Why is it needed?
=> The Checkout Field Editor provides an interface to add, edit and remove fields shown on your WooCommerce checkout page. It will help you to add/edit the fields on your checkout page.