настраиваемое поле не будет отображаться в корзине

Я создал несколько настраиваемых полей на странице своего продукта и хотел бы отобразить их в корзине, но я не могу понять, как это сделать?

Я бы хотел, чтобы поля сохранялись и отображались в корзине и в заказе администратора. Я не совсем уверен, как отображать информацию, и был бы признателен за любую помощь.

Вот мой код:

//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;

}

0

Решение

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector