| |
| <?php
|
|
|
| function d_extra_product_field(){
|
| $value = isset( $_POST['extra_product_field'] ) ? sanitize_text_field( $_POST['extra_product_field'] ) : '';
|
| printf( '<div class="custm-note-mw"><label>%s</label><br><textarea name="extra_product_field" placeholder="Briefly describe specific requirements..." value="%s"></textarea></div>', __( 'Customisation note:' ), esc_attr( $value ) );
|
| }
|
| add_action( 'woocommerce_after_add_to_cart_button', 'd_extra_product_field', 9 );
|
|
|
|
|
| function d_add_cart_item_data( $cart_item, $product_id ){
|
|
|
| if( isset( $_POST['extra_product_field'] ) ) {
|
| $cart_item['extra_product_field'] = sanitize_text_field( $_POST['extra_product_field'] );
|
| }
|
|
|
| return $cart_item;
|
|
|
| }
|
| add_filter( 'woocommerce_add_cart_item_data', 'd_add_cart_item_data', 10, 2 );
|
|
|
|
|
| function d_get_cart_data_f_session( $cart_item, $values ) {
|
|
|
| if ( isset( $values['extra_product_field'] ) ){
|
| $cart_item['extra_product_field'] = $values['extra_product_field'];
|
| }
|
|
|
| return $cart_item;
|
|
|
| }
|
| add_filter( 'woocommerce_get_cart_item_from_session', 'd_get_cart_data_f_session', 20, 2 );
|
|
|
|
|
|
|
| function d_add_order_meta( $item_id, $values ) {
|
|
|
| if ( ! empty( $values['extra_product_field'] ) ) {
|
| woocommerce_add_order_item_meta( $item_id, 'extra_product_field', $values['extra_product_field'] );
|
| }
|
| }
|
| add_action( 'woocommerce_add_order_item_meta', 'd_add_order_meta', 10, 2 );
|
|
|
|
|
| function d_get_itemdata( $other_data, $cart_item ) {
|
|
|
| if ( isset( $cart_item['extra_product_field'] ) ){
|
|
|
| $other_data[] = array(
|
| 'name' => __( 'Your extra field text' ),
|
| 'value' => sanitize_text_field( $cart_item['extra_product_field'] )
|
| );
|
|
|
| }
|
|
|
| return $other_data;
|
|
|
| }
|
| add_filter( 'woocommerce_get_item_data', 'd_get_itemdata', 10, 2 );
|
|
|
|
|
|
|
| function d_dis_metadata_order( $cart_item, $order_item ){
|
|
|
| if( isset( $order_item['extra_product_field'] ) ){
|
| $cart_item_meta['extra_product_field'] = $order_item['extra_product_field'];
|
| }
|
|
|
| return $cart_item;
|
|
|
| }
|
| add_filter( 'woocommerce_order_item_product', 'd_dis_metadata_order', 10, 2 );
|
|
|
| function d_order_email_data( $fields ) {
|
| $fields['extra_product_field'] = __( 'Your extra field text' );
|
| return $fields;
|
| }
|
| add_filter('woocommerce_email_order_meta_fields', 'd_order_email_data');
|
|
|
|
|
| function d_order_again_meta_data( $cart_item, $order_item, $order ){
|
|
|
| if( isset( $order_item['extra_product_field'] ) ){
|
| $cart_item_meta['extra_product_field'] = $order_item['extra_product_field'];
|
| }
|
|
|
| return $cart_item;
|
|
|
| }
|
| add_filter( 'woocommerce_order_again_cart_item_data', 'd_order_again_meta_data', 10, 3 );
|
| |
| |
Comments