Problem: I am using CRED Commerce to create new Users. I would like to capture the User's first name, last name, address, and email address in the CRED User form, then pre-populate the checkout fields with that information.
Solution: This will require custom code using the CRED Commerce API cred_commerce_form_action:
Within the callback function, you will have access to anything captured by the form in the $_POST superglobal. You can use that information to construct a checkout URL with custom URL parameters, then trigger a redirect to the custom URL - something like
yoursite.com/checkout?first=John&last=Smith&address=123&email=abc
Then in your filter, you can access those variables from the $_GET superglobal. Here's a very simple 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 woocommerce_checkout-fields 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; }
I'm not able to provide support for the woocommerce_checkout_fields API, because it is not part of our software. You should consult the WooCommerce documentation for more information there.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_form_action
https://docs.woocommerce.com/document/checkout-field-editor/
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 replies, has 3 voices.
Last updated by 6 years, 11 months ago.
Assisted by: Christian Cox.