=================================================== ========== FOR DEVELOPER REFERENCE ONLY =========== =================================================== Elements enable/disable description tab enable/disable reviews tab Styling Primary Buttons Add To Cart Secondary Buttons Apply Coupon Update Cart Quantity Input Field PRO - Table (Cart Page and Checkout Page) Table Border Style and Color Header Text Color Header Background Color Font Size Font Weight Text Alignment Input & Drop Down Field Border Padding Color Etc. add_action( 'woocommerce_checkout_after_customer_details' ,'kia_extra_checkout_fields' ); /*********************** Backend **********************/ // save the extra field when checkout is processed function kia_save_extra_checkout_fields( $order_id, $posted ){ // don't forget appropriate sanitization if you are using a different field type if( isset( $posted['some_field'] ) ) { update_post_meta( $order_id, '_some_field', sanitize_text_field( $posted['some_field'] ) ); } if( isset( $posted['another_field'] ) && in_array( $posted['another_field'], array( 'a', 'b', 'c' ) ) ) { update_post_meta( $order_id, '_another_field', $posted['another_field'] ); } } add_action( 'woocommerce_checkout_update_order_meta', 'kia_save_extra_checkout_fields', 10, 2 ); // display the extra data on order recieved page and my-account order review function kia_display_order_data( $order_id ){ ?>

' . __( 'Some field' ) . ':' . get_post_meta( $order->id, '_some_field', true ) . '

'; echo '

' . __( 'Another field' ) . ':' . get_post_meta( $order->id, '_another_field', true ) . '

'; echo 'Extra: ' . get_post_meta( $order->id, 'my_field_name', true ); ?>
__( 'Some field' ), 'value' => get_post_meta( $order->id, '_some_field', true ), ); $fields['another_field'] = array( 'label' => __( 'Another field' ), 'value' => get_post_meta( $order->id, '_another_field', true ), ); return $fields; } add_filter('woocommerce_email_order_meta_fields', 'kia_email_order_meta_keys', 10, 3 ); function kia_display_email_order_meta( $order, $sent_to_admin, $plain_text ) { $some_field = get_post_meta( $order->id, '_some_field', true ); $another_field = get_post_meta( $order->id, '_another_field', true ); if( $plain_text ){ echo 'The value for some field is ' . $some_field . ' while the value of another field is ' . $another_field; } else { echo '

The value for some field is ' . $some_field. ' while the value of another field is ' . $another_field .'

'; } } add_action('woocommerce_email_customer_details', 'kia_display_email_order_meta', 30, 3 ); /******************** Backend 2 *************/ /** * Validate the custom field with custom message. */ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { // Check if set, if its not set add an error. if ( ! $_POST['my_field_name'] ) wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' ); } /** * Save the order meta with field value */ 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['my_field_name'] ) ) { update_post_meta( $order_id, 'my_field_name', sanitize_text_field( $_POST['my_field_name'] ) ); } } /** * Display field value on the order edit page */ add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 ); function my_custom_checkout_field_display_admin_order_meta($order){ echo '

'.__('Extra Information').': ' . get_post_meta( $order->id, 'my_field_name', true ) . '

'; } // HOOKS //woocommerce_before_checkout_shipping_form //woocommerce_after_checkout_shipping_form //woocommerce_before_order_notes //woocommerce_after_order_notes //woocommerce_before_checkout_billing_form //woocommerce_after_checkout_billing_form //woocommerce_before_checkout_registration_form //woocommerce_after_checkout_registration_form