in functions
// get from session your URL variable and add it to item add_filter('woocommerce_get_cart_item_from_session', 'cart_item_from_session', 10, 3); function cart_item_from_session( $data, $values, $key ) { $data['text'] = isset( $values['text'] ) ? $values['text'] : ''; return $data; } // this one does the same as woocommerce_update_cart_action() in plugins\woocommerce\woocommerce-functions.php // but with your URL variable // this might not be the best way but it works add_action( 'wp_loaded', 'update_cart_action', 99); function update_cart_action() { global $woocommerce; if ( ( ! empty( $_POST['update_cart'] ) || ! empty( $_POST['proceed'] ) )) { $cart_totals = isset( $_POST['cart'] ) ? $_POST['cart'] : ''; if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { if ( isset( $cart_totals[ $cart_item_key ]['text'] ) ) { $woocommerce->cart->cart_contents[ $cart_item_key ]['text'] = $cart_totals[ $cart_item_key ]['text']; } } } } } // this is in Order summary. It show Url variable under product name. Same place where Variations are shown. add_filter( 'woocommerce_get_item_data', 'item_data', 10, 2 ); function item_data( $data, $cart_item ) { global $post; if ( isset( $cart_item['url'] ) && is_cart()) { $data['text'] = array('name' => 'Is jouw bestelling een cadeau? Vul hieronder dan een tekst in, dan doen wij een kaartje met jouw tekst in de doos.', 'value' => $cart_item['text']); } else { $data['text'] = array('name' => 'uw persoonlijk bericht', 'value' => $cart_item['text']); } return $data; } // this adds Url as meta in Order for item add_action ('woocommerce_add_order_item_meta', 'add_item_meta', 10, 2); function add_item_meta( $item_id, $values ) { woocommerce_add_order_item_meta( $item_id, 'Cadeau?', $values['text'] ); }
in cart.php
<td class="product-name"> <?php if ( ! $_product->is_visible() ) { echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . ' '; } else { echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s </a>', esc_url( $_product->get_permalink( $cart_item ) ), $_product->get_title() ), $cart_item, $cart_item_key ); } // Meta data echo WC()->cart->get_item_data( $cart_item ); // Backorder notification if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) { echo '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>'; } ?> <?php $html = sprintf( '<div class="url"><textarea rows="4" name="cart[%s]" value="%s" title="Url" class="input-text url text" ></textarea></div>', $cart_item_key, esc_attr( $values['text'] ) ); echo $html; ?> </td>
Leave a Reply