show custom input field 40 woocommerce single product page

Solutions on MaxInterview for show custom input field 40 woocommerce single product page by the best coders in the world

showing results for - "show custom input field 40 woocommerce single product page"
Federico
11 May 2018
1/**
2 * @snippet       Add input field to products - WooCommerce
3 * @how-to        Get CustomizeWoo.com FREE
4 * @author        Rodolfo Melogli
5 * @compatible    WooCommerce 3.9
6 * @donate $9     https://businessbloomer.com/bloomer-armada/
7 */
8 
9// -----------------------------------------
10// 1. Show custom input field above Add to Cart
11 
12add_action( 'woocommerce_before_add_to_cart_button', 'bbloomer_product_add_on', 9 );
13 
14function bbloomer_product_add_on() {
15    $value = isset( $_POST['custom_text_add_on'] ) ? sanitize_text_field( $_POST['custom_text_add_on'] ) : '';
16    echo '<div><label>Custom Text Add-On <abbr class="required" title="required">*</abbr></label><p><input name="custom_text_add_on" value="' . $value . '"></p></div>';
17}
18 
19// -----------------------------------------
20// 2. Throw error if custom input field empty
21 
22add_filter( 'woocommerce_add_to_cart_validation', 'bbloomer_product_add_on_validation', 10, 3 );
23 
24function bbloomer_product_add_on_validation( $passed, $product_id, $qty ){
25   if( isset( $_POST['custom_text_add_on'] ) && sanitize_text_field( $_POST['custom_text_add_on'] ) == '' ) {
26      wc_add_notice( 'Custom Text Add-On is a required field', 'error' );
27      $passed = false;
28   }
29   return $passed;
30}
31 
32// -----------------------------------------
33// 3. Save custom input field value into cart item data
34 
35add_filter( 'woocommerce_add_cart_item_data', 'bbloomer_product_add_on_cart_item_data', 10, 2 );
36 
37function bbloomer_product_add_on_cart_item_data( $cart_item, $product_id ){
38    if( isset( $_POST['custom_text_add_on'] ) ) {
39        $cart_item['custom_text_add_on'] = sanitize_text_field( $_POST['custom_text_add_on'] );
40    }
41    return $cart_item;
42}
43 
44// -----------------------------------------
45// 4. Display custom input field value @ Cart
46 
47add_filter( 'woocommerce_get_item_data', 'bbloomer_product_add_on_display_cart', 10, 2 );
48 
49function bbloomer_product_add_on_display_cart( $data, $cart_item ) {
50    if ( isset( $cart_item['custom_text_add_on'] ) ){
51        $data[] = array(
52            'name' => 'Custom Text Add-On',
53            'value' => sanitize_text_field( $cart_item['custom_text_add_on'] )
54        );
55    }
56    return $data;
57}
58 
59// -----------------------------------------
60// 5. Save custom input field value into order item meta
61 
62add_action( 'woocommerce_add_order_item_meta', 'bbloomer_product_add_on_order_item_meta', 10, 2 );
63 
64function bbloomer_product_add_on_order_item_meta( $item_id, $values ) {
65    if ( ! empty( $values['custom_text_add_on'] ) ) {
66        wc_add_order_item_meta( $item_id, 'Custom Text Add-On', $values['custom_text_add_on'], true );
67    }
68}
69 
70// -----------------------------------------
71// 6. Display custom input field value into order table
72 
73add_filter( 'woocommerce_order_item_product', 'bbloomer_product_add_on_display_order', 10, 2 );
74 
75function bbloomer_product_add_on_display_order( $cart_item, $order_item ){
76    if( isset( $order_item['custom_text_add_on'] ) ){
77        $cart_item['custom_text_add_on'] = $order_item['custom_text_add_on'];
78    }
79    return $cart_item;
80}
81 
82// -----------------------------------------
83// 7. Display custom input field value into order emails
84 
85add_filter( 'woocommerce_email_order_meta_fields', 'bbloomer_product_add_on_display_emails' );
86 
87function bbloomer_product_add_on_display_emails( $fields ) { 
88    $fields['custom_text_add_on'] = 'Custom Text Add-On';
89    return $fields; 
90}
91
queries leading to this page
how to add custom fields to woocommerce product pagehow to add custom field in woocommerce single product page in pluginwoocommerce add custom field productwoocommerce get product by custom fieldadd custom input field on woocommerce cart pagehow to add custom field in woocommerce product page details pagewoocommerce custom values to product formhow to add custom field in woocommerce product page show product tabadd custom product field woocommerceadd feild on product page woocommercehow to display custom field value on woocommerce product pageadd custom field woocommerce productcustom input fields for woocommerce productshow to get custom field value in woocommerce product pagewoocommerce extra product fieldwoocommerce product custom fielddisplay custom field in single product page woocommercecustom product fields woocommerceshow acf field woocommerce producthow to get woocommerce product with custom fieldshow to input field in woocommerce productwoocommerce add custom field to variable productwoocommerce single product custom fieldswoocommerce product additional fieldsadd product field woocommerceadd custom field woocommerce product pagewoocommerce product add custom fieldcustom field in woocommerce product with codehow to input field in woocommerce product datahow to add simple input field custom meta box in woocommerce productwoocommerce add product fieldadd custom field to custom product woocommerce by phphow to add custom field in woocommerce productwoocommerce add input field to product pagecustom fields woocommerce product pagehow to add custom input field in woocommerce product pageadd field to woocommerce single product pagecustom product input fields woocommercecustom field on single product woocommerceadd custom input field in single product page woocommerceadd field in woocommerce product pageadd custom field in product page in wordpress woocommerce singleinput field on product page woocomnmercecreate woocommerce product custom field programmaticallyadd custom feilds in woocommerce single product pageproduct input fields for woocommercehow to use extra field in woocomerce product page 3fadd option field in single product page woocommercewoocommerce add extra verition fileds with form how to add custom field in woocommerce product categorycreate custom input field in product page woocommercewoocommerce add extra fileds to productadd custom field in woocommerce single product page without pluginadd on fields woocommerce productadd dynamic custom field in woocommerce single product pageadd fields to product page woocommerce pluginhow to add custom field to product in woocommercehow to add custom field in woocommerce product pagehow to add custom input field in woocommerce product page woocommerce comshow custom input field 40 woocommerce single product pageget custom field from product woocommercehow to add custom field in product variation woocommerceadd a custom field in variation in woocommerce producthow to call custom field value woocommerce product in wordpressadd custom field on single product woocommerceadd custom field in product page in wordpress woocommercewoocommerce custom fields product pageadd custom field in wordpress woocommerce productcustom product description field woocommerceadd form field in single product page woocommerceadd custom field in the woocomerce single product pagewoocommerce add custom product field tabadd custom text field on single product woocommercewoocommerce input field productadd custom field button woocommerce product pagehow to show custom field value in category in woocommerce product pagehow to display custom field in woocommerce product pagewoocommerce product user input fieldcustom product field woocommercewoocommerce add input field to product page add to cardadd additional field in product variation 2b woocommercewoocommerce additional product fieldsget woocommerce product with custom field in single blog postwoocommerce add product fieldshow to add input field on single product page in woocommercewoocommerce add input field to productshow custom fields on woocommerce product pageget additional input from the customer in woocommerce product pageadd more field on single product page in woocommerceshow custom variation field value on product page 2b woocommercewoocommerce custom fields product page show on product details pagewoocommerce add custom field to product programmaticallywoocommerce get custom product fieldshow custom input field 40 woocommerce single product page