Last active
July 21, 2022 19:16
Revisions
-
nadeem-khan revised this gist
Sep 4, 2014 . 1 changed file with 26 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,10 +17,10 @@ * Add a custom field in shipping checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_shipping_checkout_fields'); // Our hooked in function - $fields is passed via the filter! function custom_override_shipping_checkout_fields($fields) { $fields['shipping']['shipping_location_type'] = array( 'type' => 'select', 'label' => __('Location Type', 'woocommerce'), @@ -55,16 +55,16 @@ function custom_override_shipping_checkout_fields($fields) { ); return $fields; } /** * Add a custom field in billing checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_billing_checkout_fields'); // Our hooked in function - $fields is passed via the filter! function custom_override_billing_checkout_fields($fields) { $fields['billing']['billing_location_type'] = array( 'type' => 'select', 'label' => __('Location Type', 'woocommerce'), @@ -83,14 +83,14 @@ function custom_override_billing_checkout_fields($fields) { ); return $fields; } /** * Order all the fields as per requirement * */ add_filter("woocommerce_checkout_fields", "order_shipping_fields"); function order_shipping_fields($fields) { $order = array( "shipping_country", @@ -112,11 +112,11 @@ function order_shipping_fields($fields) { $fields["shipping"] = $ordered_fields; unset($fields['order']['order_comments']); return $fields; } add_filter("woocommerce_checkout_fields", "order_billing_fields"); function order_billing_fields($fields) { $order = array( "billing_country", @@ -137,14 +137,14 @@ function order_billing_fields($fields) { $fields["billing"] = $ordered_fields; return $fields; } /** * Add custom field in custom area (other than shipping and billing forms) * */ add_action('woocommerce_after_order_notes', 'personal_message_checkout_field'); function personal_message_checkout_field($checkout) { echo '<div class="delivery-notice-container">*Orders for delivery received AFTER 12PM may ship the next business day.</div>'; echo '<h3 class="entry-title">' . __('WRITE A PERSONAL MESSAGE') . '</h3>'; echo '<div class="entry-wrapper">'; @@ -185,14 +185,14 @@ function personal_message_checkout_field($checkout) { 'required' => true ), substr($checkout->get_value('your_message'), 200)); echo '</div>'; } /** * Process the checkout * */ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { if ($_POST['shipping']['shipping_location_type'] == "select") { wc_add_notice(__('Please tell us the Location Type we are delivering to.'), 'error'); @@ -209,14 +209,14 @@ function my_custom_checkout_field_process() { if (!$_POST['your_message']) { wc_add_notice(__('Please tell us the Message that we have to enter in your card.'), 'error'); } } /** * Update the order meta with custom fields values * */ add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); function my_custom_checkout_field_update_order_meta($order_id) { if (!empty($_POST['shipping']['shipping_location_type'])) { update_post_meta($order_id, 'Location Type', esc_attr($_POST['shipping']['shipping_location_type'])); @@ -231,27 +231,27 @@ function my_custom_checkout_field_update_order_meta($order_id) { if (!empty($_POST['your_message'])) { update_post_meta($order_id, 'Your Message', sanitize_text_field($_POST['your_message'])); } } /** * Display Custom Shipping fields and custom fields in custom area in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); function my_custom_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Email') . ':</strong><br> ' . get_post_meta($order->id, '_shipping_email', true) . '</p>'; echo '<p><strong>' . __('Phone') . ':</strong><br> ' . get_post_meta($order->id, '_shipping_phone', true) . '</p>'; echo '<p><strong>' . __('Location Type') . ':</strong><br> ' . get_post_meta($order->id, '_shipping_location_type', true) . '</p>'; echo "<h4>Personal Message</h4>"; echo '<p><strong>' . __('Card Type') . ':</strong><br> ' . get_post_meta($order->id, 'Card Type', true) . '</p>'; echo '<p><strong>' . __('Your Message') . ':</strong><br> ' . get_post_meta($order->id, 'Your Message', true) . '</p>'; } /** * Display Custom Billing fields in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); function my_custom_billing_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Location Type') . ':</strong><br> ' . get_post_meta($order->id, '_billing_location_type', true) . '</p>'; } -
nadeem-khan revised this gist
Sep 4, 2014 . 1 changed file with 15 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,17 +4,17 @@ /** * Plugin Name: Flowershop - WooCommerceCustomOverrides * Plugin URI: http://chillopedia.com * Description: Overrides WooCommerce Checkout Form Fields * Version: 1.0 * Author: Nadeem Khan * Author URI: http://facebook.com/nadeem.khan * License: GPL */ /** * Add a custom field in shipping checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_shipping_checkout_fields'); @@ -58,7 +58,7 @@ function custom_override_shipping_checkout_fields($fields) { } /** * Add a custom field in billing checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_billing_checkout_fields'); @@ -86,7 +86,7 @@ function custom_override_billing_checkout_fields($fields) { } /** * Order all the fields as per requirement * */ add_filter("woocommerce_checkout_fields", "order_shipping_fields"); @@ -140,7 +140,7 @@ function order_billing_fields($fields) { } /** * Add custom field in custom area (other than shipping and billing forms) * */ add_action('woocommerce_after_order_notes', 'personal_message_checkout_field'); @@ -188,7 +188,7 @@ function personal_message_checkout_field($checkout) { } /** * Process the checkout * */ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); @@ -212,7 +212,7 @@ function my_custom_checkout_field_process() { } /** * Update the order meta with custom fields values * */ add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); @@ -234,7 +234,7 @@ function my_custom_checkout_field_update_order_meta($order_id) { } /** * Display Custom Shipping fields and custom fields in custom area in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); @@ -248,7 +248,7 @@ function my_custom_fields_display_admin_order_meta($order) { } /** * Display Custom Billing fields in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); -
nadeem-khan revised this gist
Sep 4, 2014 . 1 changed file with 22 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,23 +3,23 @@ <?php /** * Plugin Name: Flowershop - WooCommerceCustomOverrides * Plugin URI: http://chillopedia.com * Description: Overrides WooCommerce Checkout Form Fields * Version: 1.0 * Author: Nadeem Khan * Author URI: http://facebook.com/nadeem.khan * License: GPL */ /** * Add a custom field in shipping checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_shipping_checkout_fields'); // Our hooked in function - $fields is passed via the filter! function custom_override_shipping_checkout_fields($fields) { $fields['shipping']['shipping_location_type'] = array( 'type' => 'select', @@ -57,13 +57,13 @@ function custom_override_shipping_checkout_fields($fields) { return $fields; } /** * Add a custom field in billing checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_billing_checkout_fields'); // Our hooked in function - $fields is passed via the filter! function custom_override_billing_checkout_fields($fields) { $fields['billing']['billing_location_type'] = array( 'type' => 'select', @@ -85,9 +85,9 @@ function custom_override_billing_checkout_fields($fields) { return $fields; } /** * Order all the fields as per requirement * */ add_filter("woocommerce_checkout_fields", "order_shipping_fields"); function order_shipping_fields($fields) { @@ -139,9 +139,9 @@ function order_billing_fields($fields) { return $fields; } /** * Add custom field in custom area (other than shipping and billing forms) * */ add_action('woocommerce_after_order_notes', 'personal_message_checkout_field'); function personal_message_checkout_field($checkout) { @@ -187,9 +187,9 @@ function personal_message_checkout_field($checkout) { echo '</div>'; } /** * Process the checkout * */ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { @@ -211,9 +211,9 @@ function my_custom_checkout_field_process() { } } /** * Update the order meta with custom fields values * */ add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); function my_custom_checkout_field_update_order_meta($order_id) { @@ -233,9 +233,9 @@ function my_custom_checkout_field_update_order_meta($order_id) { } } /** * Display Custom Shipping fields and custom fields in custom area in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); function my_custom_fields_display_admin_order_meta($order) { @@ -247,9 +247,9 @@ function my_custom_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Your Message') . ':</strong><br> ' . get_post_meta($order->id, 'Your Message', true) . '</p>'; } /** * Display Custom Billing fields in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); function my_custom_billing_fields_display_admin_order_meta($order) { -
nadeem-khan renamed this gist
Sep 4, 2014 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ **Create Custom Fields in Woocommerce Checkout Page and Display them in Orders Details Page in Admin Area with this WordPress plugin:** <?php /** @@ -252,4 +254,4 @@ add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_bill function my_custom_billing_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Location Type') . ':</strong><br> ' . get_post_meta($order->id, '_billing_location_type', true) . '</p>'; } -
nadeem-khan revised this gist
Sep 2, 2014 . 1 changed file with 23 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,9 @@ * License: GPL */ /** * Add a custom field in shipping checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_shipping_checkout_fields'); @@ -54,6 +55,9 @@ function custom_override_shipping_checkout_fields($fields) { return $fields; } /** * Add a custom field in billing checkout form * */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_billing_checkout_fields'); @@ -79,6 +83,9 @@ function custom_override_billing_checkout_fields($fields) { return $fields; } /** * Order all the fields as per requirement * */ add_filter("woocommerce_checkout_fields", "order_shipping_fields"); function order_shipping_fields($fields) { @@ -131,8 +138,8 @@ function order_billing_fields($fields) { } /** * Add custom field in custom area (other than shipping and billing forms) * */ add_action('woocommerce_after_order_notes', 'personal_message_checkout_field'); function personal_message_checkout_field($checkout) { @@ -178,6 +185,9 @@ function personal_message_checkout_field($checkout) { echo '</div>'; } /** * Process the checkout * */ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { @@ -199,6 +209,9 @@ function my_custom_checkout_field_process() { } } /** * Update the order meta with custom fields values * */ add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); function my_custom_checkout_field_update_order_meta($order_id) { @@ -218,6 +231,9 @@ function my_custom_checkout_field_update_order_meta($order_id) { } } /** * Display Custom Shipping fields and custom fields in custom area in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); function my_custom_fields_display_admin_order_meta($order) { @@ -229,6 +245,9 @@ function my_custom_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Your Message') . ':</strong><br> ' . get_post_meta($order->id, 'Your Message', true) . '</p>'; } /** * Display Custom Billing fields in the Order details area in Woocommerce->orders * */ add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); function my_custom_billing_fields_display_admin_order_meta($order) { -
nadeem-khan revised this gist
Sep 2, 2014 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -136,7 +136,7 @@ function order_billing_fields($fields) { add_action('woocommerce_after_order_notes', 'personal_message_checkout_field'); function personal_message_checkout_field($checkout) { echo '<div class="delivery-notice-container">*Orders for delivery received AFTER 12PM may ship the next business day.</div>'; echo '<h3 class="entry-title">' . __('WRITE A PERSONAL MESSAGE') . '</h3>'; echo '<div class="entry-wrapper">'; @@ -186,6 +186,10 @@ function my_custom_checkout_field_process() { wc_add_notice(__('Please tell us the Location Type we are delivering to.'), 'error'); } if ($_POST['billing']['billing_location_type'] == "select") { wc_add_notice(__('Please tell us the Location Type that we are billing to.'), 'error'); } if (!$_POST['card_type']) { wc_add_notice(__('Please tell us the type of the Card that we have to deliver.'), 'error'); } @@ -202,6 +206,10 @@ function my_custom_checkout_field_update_order_meta($order_id) { if (!empty($_POST['shipping']['shipping_location_type'])) { update_post_meta($order_id, 'Location Type', esc_attr($_POST['shipping']['shipping_location_type'])); } if (!empty($_POST['billing']['billing_location_type'])) { update_post_meta($order_id, 'Location Type', esc_attr($_POST['billing']['billing_location_type'])); } if (!empty($_POST['card_type'])) { update_post_meta($order_id, 'Card Type', sanitize_text_field($_POST['card_type'])); } @@ -220,3 +228,9 @@ function my_custom_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Card Type') . ':</strong><br> ' . get_post_meta($order->id, 'Card Type', true) . '</p>'; echo '<p><strong>' . __('Your Message') . ':</strong><br> ' . get_post_meta($order->id, 'Your Message', true) . '</p>'; } add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1); function my_custom_billing_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Location Type') . ':</strong><br> ' . get_post_meta($order->id, '_billing_location_type', true) . '</p>'; } -
nadeem-khan revised this gist
Sep 2, 2014 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ <?php /** * Plugin Name: Flowershop - WooCommerceCustomOverrides * Plugin URI: http://chillopedia.com @@ -9,6 +10,9 @@ * Author URI: http://facebook.com/nadeem.khan * License: GPL */ //Save this as a php file in a folder (with any name) under wp-content/plugins/ and then activate the plugin to both add custom fields and reorder the fields in woocommerce checkout form: // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_shipping_checkout_fields'); @@ -209,7 +213,10 @@ function my_custom_checkout_field_update_order_meta($order_id) { add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); function my_custom_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Email') . ':</strong><br> ' . get_post_meta($order->id, '_shipping_email', true) . '</p>'; echo '<p><strong>' . __('Phone') . ':</strong><br> ' . get_post_meta($order->id, '_shipping_phone', true) . '</p>'; echo '<p><strong>' . __('Location Type') . ':</strong><br> ' . get_post_meta($order->id, '_shipping_location_type', true) . '</p>'; echo "<h4>Personal Message</h4>"; echo '<p><strong>' . __('Card Type') . ':</strong><br> ' . get_post_meta($order->id, 'Card Type', true) . '</p>'; echo '<p><strong>' . __('Your Message') . ':</strong><br> ' . get_post_meta($order->id, 'Your Message', true) . '</p>'; } -
nadeem-khan created this gist
Sep 2, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,215 @@ <?php /** * Plugin Name: Flowershop - WooCommerceCustomOverrides * Plugin URI: http://chillopedia.com * Description: Overrides WooCommerce Checkout Form Fields * Version: 1.0 * Author: Nadeem Khan * Author URI: http://facebook.com/nadeem.khan * License: GPL */ // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_shipping_checkout_fields'); // Our hooked in function - $fields is passed via the filter! function custom_override_shipping_checkout_fields($fields) { $fields['shipping']['shipping_location_type'] = array( 'type' => 'select', 'label' => __('Location Type', 'woocommerce'), 'clear' => false, 'options' => array( 'home' => __('Home', 'woocommerce'), 'apartment' => __('Apartment', 'woocommerce'), 'business' => __('Business', 'woocommerce'), 'hospital' => __('Hospital', 'woocommerce'), 'funeral-home' => __('Funeral Home', 'woocommerce'), 'church' => __('Church', 'woocommerce'), 'other' => __('Other', 'woocommerce') ), 'placeholder' => _x('Location Type', 'placeholder', 'woocommerce'), 'required' => true ); $fields['shipping']['shipping_email'] = array( 'type' => 'text', 'label' => __('Email Address', 'woocommerce'), 'clear' => false, 'placeholder' => _x('Enter Email', 'placeholder', 'woocommerce'), 'required' => true ); $fields['shipping']['shipping_phone'] = array( 'type' => 'text', 'label' => __('Phone', 'woocommerce'), 'clear' => false, 'placeholder' => _x('Enter Phone Number', 'placeholder', 'woocommerce'), 'required' => true ); return $fields; } // Hook in add_filter('woocommerce_checkout_fields', 'custom_override_billing_checkout_fields'); // Our hooked in function - $fields is passed via the filter! function custom_override_billing_checkout_fields($fields) { $fields['billing']['billing_location_type'] = array( 'type' => 'select', 'label' => __('Location Type', 'woocommerce'), 'clear' => false, 'options' => array( 'home' => __('Home', 'woocommerce'), 'apartment' => __('Apartment', 'woocommerce'), 'business' => __('Business', 'woocommerce'), 'hospital' => __('Hospital', 'woocommerce'), 'funeral-home' => __('Funeral Home', 'woocommerce'), 'church' => __('Church', 'woocommerce'), 'other' => __('Other', 'woocommerce') ), 'placeholder' => _x('Location Type', 'placeholder', 'woocommerce'), 'required' => true ); return $fields; } add_filter("woocommerce_checkout_fields", "order_shipping_fields"); function order_shipping_fields($fields) { $order = array( "shipping_country", "shipping_first_name", "shipping_last_name", "shipping_location_type", "shipping_address_1", "shipping_address_2", "shipping_city", "shipping_state", "shipping_postcode", "shipping_email", "shipping_phone" ); foreach ($order as $field) { $ordered_fields[$field] = $fields["shipping"][$field]; } $fields["shipping"] = $ordered_fields; unset($fields['order']['order_comments']); return $fields; } add_filter("woocommerce_checkout_fields", "order_billing_fields"); function order_billing_fields($fields) { $order = array( "billing_country", "billing_first_name", "billing_last_name", "billing_location_type", "billing_address_1", "billing_address_2", "billing_city", "billing_state", "billing_postcode", "billing_email", "billing_phone" ); foreach ($order as $field) { $ordered_fields[$field] = $fields["billing"][$field]; } $fields["billing"] = $ordered_fields; return $fields; } /** * Add the field to the checkout */ add_action('woocommerce_after_order_notes', 'personal_message_checkout_field'); function personal_message_checkout_field($checkout) { echo '<h3 class="entry-title">' . __('WRITE A PERSONAL MESSAGE') . '</h3>'; echo '<div class="entry-wrapper">'; woocommerce_form_field('card_type', array( 'type' => 'select', 'class' => array('form-row-wide'), 'label' => __('Select the card type'), 'clear' => false, 'options' => array( 'anniversary' => __('Anniversary', 'woocommerce'), 'birthday' => __('Birthday', 'woocommerce'), 'business-gift' => __('Business Gift', 'woocommerce'), 'congratulations' => __('Congratulations', 'woocommerce'), 'funeral' => __('Funeral', 'woocommerce'), 'get-well' => __('Get Well', 'woocommerce'), 'grandparents-day' => __('Grandparents Day', 'woocommerce'), 'housewarming' => __('Housewarming', 'woocommerce'), 'imsorry' => __('I\'m Sorry', 'woocommerce'), 'just-because' => __('Just Because', 'woocommerce'), 'love-and-romance' => __('Love & Romance', 'woocommerce'), 'new-baby' => __('New Baby', 'woocommerce'), 'retirement' => __('Retirement', 'woocommerce'), 'sympathy' => __('Sympathy', 'woocommerce'), 'thank-you' => __('Thank You', 'woocommerce'), 'thinking-of-you' => __('Thinking of You', 'woocommerce'), 'other' => __('Other', 'woocommerce') ), 'required' => true, 'placeholder' => __('Select card type'), ), $checkout->get_value('card_type')); woocommerce_form_field('your_message', array( 'type' => 'textarea', 'class' => array('form-row form-row-wide'), 'label' => __('Your Message'), 'placeholder' => __('Enter your message (must be less than 200 characters)'), 'required' => true ), substr($checkout->get_value('your_message'), 200)); echo '</div>'; } add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { if ($_POST['shipping']['shipping_location_type'] == "select") { wc_add_notice(__('Please tell us the Location Type we are delivering to.'), 'error'); } if (!$_POST['card_type']) { wc_add_notice(__('Please tell us the type of the Card that we have to deliver.'), 'error'); } if (!$_POST['your_message']) { wc_add_notice(__('Please tell us the Message that we have to enter in your card.'), 'error'); } } add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); function my_custom_checkout_field_update_order_meta($order_id) { if (!empty($_POST['shipping']['shipping_location_type'])) { update_post_meta($order_id, 'Location Type', esc_attr($_POST['shipping']['shipping_location_type'])); } if (!empty($_POST['card_type'])) { update_post_meta($order_id, 'Card Type', sanitize_text_field($_POST['card_type'])); } if (!empty($_POST['your_message'])) { update_post_meta($order_id, 'Your Message', sanitize_text_field($_POST['your_message'])); } } add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_fields_display_admin_order_meta', 10, 1); function my_custom_fields_display_admin_order_meta($order) { echo '<p><strong>' . __('Location Type') . ':</strong> ' . get_post_meta($order->id, '_shipping_location_type', true) . '</p>'; echo '<p><strong>' . __('Card Type') . ':</strong> ' . get_post_meta($order->id, 'Card Type', true) . '</p>'; echo '<p><strong>' . __('Your Message') . ':</strong> ' . get_post_meta($order->id, 'Your Message', true) . '</p>'; }