Я создал некоторые пользовательские поля на моей странице продукта и хотел бы показать их в корзине, но для жизни меня не могу понять, как это сделать?пользовательское поле не отображается в корзине
Я бы хотел, чтобы поля были сохранены и отображены на тележке и в порядке администратора. Я не совсем уверен, как отображать информацию и буду признателен за любую помощь.
Вот мой код:
//add the fields to the form
add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
function my_custom_checkout_field($fields) {
echo '<table class="table variations">
<tr>
<td class="label"><label class="control-label span3" for="inputTextone">'.__('Text Line 1', 'woocommerce').' </label></td>
<td class="value"><input type="text" name="text_line_1" id="inputTextone" class="span11"></td>
</tr>
<tr>
<td class="label"><label class="control-label span3" for="inputTexttwo">'.__('Text Line 2', 'woocommerce').' </label></td>
<td class="value"><input type="text" name="text_line_2" id="inputTexttwo" class="span11"></td>
</tr>
<tr>
<td class="label"><label class="control-label span3">'.__('Additional Info', 'woocommerce').' </label></td>
<td class="value"><input type="text" name="additional_info" id="inputAdditional" class="span11"></td>
</tr>
</table>';
}
//Store the custom field
add_filter('woocommerce_add_cart_item_data', 'add_cart_item_custom_data_vase', 10, 2);
function add_cart_item_custom_data_vase($cart_item_meta, $product_id) {
global $woocommerce;
$cart_item_meta['text_line_1'] = $_POST['text_line_1'];
$cart_item_meta['text_line_2'] = $_POST['text_line_2'];
$cart_item_meta['additional_info'] = $_POST['additional_info'];
return $cart_item_meta;
}
//add the data to the session
add_filter('woocommerce_get_cart_item_from_session', 'get_cart_items_from_session', 1, 3);
function get_cart_items_from_session($item, $values, $key) {
if (array_key_exists('text_line_1', $values)) {
$item['text_line_1'] = $values['text_line_1'];
}
return $item;
}
//display the data on the cart page
add_filter('woocommerce_get_item_data', 'show_custom_data');
function show_cart_data($custom_fields) {
$custom_fields['text_line_1'] = $_POST['text_line_1'];
return $custom_fields;
}
Спасибо @mycholan, это именно то, что мне нужно. – fnk
@fnk рад, что это помогло. – Sark
Единственное, что я заметил, это то, что ярлыки отображаются как name_on_tshirt, а не имя на tshirt – fnk