I'm trying to pass some metadata from the products page to the invoice page to show the users after they check out.
I've got everything to work apart from the getting the actual data the user has inputed from the $POST as you can see below.
Add to cart function - $POST problem is here
add_filter('woocommerce_add_cart_item_data','wdm_add_item_data',1,10);
function wdm_add_item_data($cart_item_data, $product_id) {
global $woocommerce;
$new_value = array();
$new_value['chest'] = "This Works"; //but
$new_value['shoulders'] = $_POST['shoulders']; //This doesn't
if(empty($cart_item_data)) {
return $new_value;
} else {
return array_merge($cart_item_data, $new_value);
}
}
HTML
<tr>
<th>
<label for="chest" id="chest_text">
<?php _e('Chest Width (inches)', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="chest" id="chest" value="<?php if (!$user_ID==0) {echo esc_attr( get_the_author_meta( 'chest', $user_ID ));} ?>" class="regular-text" /><br />
</td>
</tr>
<tr>
<th>
<label for="shoulders" id="shoulders_text">
<?php _e('Shoulder Width (inches)', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="shoulders" id="shoulders" value="<?php if (!$user_ID==0) {echo esc_attr( get_the_author_meta( 'shoulders', $user_ID ));} ?>" class="regular-text" /><br />
</td>
</tr>
I have ajax enabled on the add to cart button and I know the code runs because hard coded string get passed through and displayed on the invoice but I don't see why the POST isn't delivering the data the user has entered.
FULL HTML
<table class="form-table">
<tr>
<th>
<label for="chest">
<?php _e('Chest Width', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="chest" id="chest" value="<?php echo esc_attr( get_the_author_meta( 'chest', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your chest width.', 'eribootstrap'); ?></span>
</td>
</tr><!-- field ends here -->
<tr>
<th>
<label for="shoulders">
<?php _e('Shoulder Width', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="shoulders" id="shoulders" value="<?php echo esc_attr( get_the_author_meta( 'shoulders', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your shoulders.', 'eribootstrap'); ?></span>
</td>
</tr><!-- field ends here -->
<tr>
<th>
<label for="sleeve">
<?php _e('Sleeve Length', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="sleeve" id="sleeve" value="<?php echo esc_attr( get_the_author_meta( 'sleeve', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your sleeve length.', 'eribootstrap'); ?></span>
</td>
</tr><!-- field ends here -->
<tr>
<th>
<label for="arm">
<?php _e('Arm Length', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="arm" id="arm" value="<?php echo esc_attr( get_the_author_meta( 'arm', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your arm length.', 'eribootstrap'); ?></span>
</td>
</tr><!-- field ends here -->
<tr>
<th>
<label for="highwaist">
<?php _e('High Waist', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="highwaist" id="highwaist" value="<?php echo esc_attr( get_the_author_meta( 'highwaist', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your high waist measurement.', 'eribootstrap'); ?></span>
</td>
</tr><!-- field ends here -->
<tr>
<th>
<label for="lowwaist">
<?php _e('Low Waist', 'eribootstrap'); ?>
</label>
</th>
<td>
<input type="text" name="lowwaist" id="lowwaist" value="<?php echo esc_attr( get_the_author_meta( 'lowwaist', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your low waist measurement.', 'eribootstrap'); ?></span>
</td>
</tr><!-- field ends here -->
</table>
EDIT: fixed a typo.
EDIT 2: Added full HTML