不能得到$_POST值woocommerce添加到购物车挂钩


Can't get $_POST value in woocommerce add to cart hook

我试图将一些元数据从产品页面传递到发票页面,以便在用户结账后显示。

除了从$POST中获取用户输入的实际数据之外,我已经完成了所有工作,如下所示。

添加到购物车功能- $POST问题在这里

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>

我在添加到购物车按钮上启用了ajax,我知道代码运行,因为硬编码字符串通过并显示在发票上,但我不明白为什么POST不传递用户输入的数据。

完整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 2:添加完整的HTML

我想这只是一个打字错误。HTML上写的是"肩膀",而PHP代码上写的是"肩膀"。使用浏览器的开发工具或PHP调试器检查发布的内容。