Capturing posted variables at Place Order (WooCommerce Checkout)
-
I’m trying to add new variables to be posted when “Place Order” is submitted via checkout. These variables are then to be captured and added to product post_meta (with add_post_meta). However, I have found that $_POST variables simply are not captured, and may somehow be cleared by WooCommerce.
I am wondering if a) PLACE ORDER clears all $_POST variables somehow. If so, b), can that behavior be bypassed directly, or do I c) have to place the form in a new area independent of PLACE ORDER, so it is submitted separately, or d) is it some completely other problem?
To give simplified versions of the form submit code and add_post_meta code I’m using, the first looks something like this (the brackets on the name variable are so that the fields can accept arrays via multiple input actions):
echo ' <input type="text" name="first_name[]" id="first_name" />'; echo ' <input type="text" name="last_name[]" id="last_name" />';
The lines are added to Woo checkout – after the action woocommerce_checkout_after_customer_details – with a function that also grabs the post ID for the product, which is used in the add_post_meta() function triggered on PLACE ORDER submit. The problem is that, though add_post_meta() with send the array of keys it’s meant to send, it won’t capture $_POST variables. I’m using something like the following:
if (isset($_POST) == true) { $att_data = array( 'last_name' => $_POST['last_name'], 'first_name' => $_POST['first_name'] ); add_post_meta($event_id,'attendee_list',$att_data);
It works just fine with dummy values or as a direct addition rather than a form submit (has to be the latter because the values are user-supplied). Variable dumps of the $_POST values confirms an empty array, which shows up on post_meta as key names with NULL values.
I’ve been working on this intensively, and I think my syntax is correct, so, to return to where I’m started, is there something in the WooC Checkout/PLACE ORDER code that prevents capture of $_POST variables in this manner, and can it be counteracted or bypassed ?
- The topic ‘Capturing posted variables at Place Order (WooCommerce Checkout)’ is closed to new replies.