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
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.
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:
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?
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.