/* * Añadir casilla RUT en el checkout */ function woo_custom_field_checkout($checkout) { echo '<div id="additional_checkout_field">'; woocommerce_form_field( 'rut', array( // Identificador del campo 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'required' => true, // Aquí muestra que no es obligatorio, si queres que sea obligatorio pon 'True' en vez de 'False' 'label' => __('RUT'), // Nombre del campo 'placeholder' => __('Ej: 21.322.303-0'), // Texto guía que se muestra dentro de la celda. ), $checkout->get_value( 'rut' )); // Identificador del campo echo '</div>'; } add_action( 'woocommerce_after_checkout_billing_form', 'woo_custom_field_checkout' ); /* * INCLUYE RUT EN LOS DETALLES DEL PEDIDO CON EL NUEVO CAMPO */ function woo_custom_field_checkout_update_order($order_id) { if ( ! empty( $_POST['rut'] ) ) { update_post_meta( $order_id, 'RUT', sanitize_text_field( $_POST['rut'] ) ); } } add_action( 'woocommerce_checkout_update_order_meta', 'woo_custom_field_checkout_update_order' ); /* * MUESTRA EL VALOR DEL CAMPO RUT LA PÁGINA DE MODIFICACIÓN DEL PEDIDO */ function woo_custom_field_checkout_edit_order($order){ echo '<p><strong>'.__('RUT').':</strong> ' . get_post_meta( $order->id, 'RUT', true ) . '</p>'; } add_action( 'woocommerce_admin_order_data_after_billing_address', 'woo_custom_field_checkout_edit_order', 10, 1 ); /* * INCLUYE EL CAMPO RUT EN EL CORREO ELECTRÓNICO DE AVISO A TU CLIENTE */ function woo_custom_field_checkout_email($keys) { $keys[] = 'RUT'; return $keys; } add_filter('woocommerce_email_order_meta_keys', 'woo_custom_field_checkout_email');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter