__('NIP','woocommerce-nip'), 'placeholder' => _x('Podaj NIP jeśli będziesz potrzebować faktury', 'placeholder', 'woocommerce-nip'), 'required' => false, 'class' => array('my-field-class form-row-wide'), 'clear' => true ); // just copy same format if you’d like to add more fields return $fields; } /** * Adding address fields to user registration form **/ /** * Add new register fields for WooCommerce registration. * * @return string Register fields HTML. */ function wooc_extra_register_fields() { ?>

add( 'billing_first_name_error', __( 'First name is required!', 'woocommerce-nip' ) ); } if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) { $validation_errors->add( 'billing_last_name_error', __( 'Last name is required!.', 'woocommerce-nip' ) ); } if ( isset( $_POST['billing_address_1'] ) && empty( $_POST['billing_address_1'] ) ) { $validation_errors->add( 'billing_address_1_error', __( 'Address is required!', 'woocommerce-nip' ) ); } if ( isset( $_POST['billing_postcode'] ) && empty( $_POST['billing_postcode'] ) ) { $validation_errors->add( 'billing_postcode_error', __( 'Post code / Zip is required!.', 'woocommerce-nip' ) ); } if ( isset( $_POST['billing_city'] ) && empty( $_POST['billing_city'] ) ) { $validation_errors->add( 'billing_city_error', __( 'Town / City is required!.', 'woocommerce-nip' ) ); } } add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 ); /** * Save the extra register fields. * * @param int $customer_id Current customer ID. * * @return void */ function wooc_save_extra_register_fields( $customer_id ) { if ( isset( $_POST['billing_first_name'] ) ) { // WordPress default first name field. update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) ); // WooCommerce billing first name. update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) ); } if ( isset( $_POST['billing_last_name'] ) ) { // WordPress default last name field. update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) ); // WooCommerce billing last name. update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) ); } if ( isset( $_POST['billing_company'] ) ) { // WooCommerce billing_company update_user_meta( $customer_id, 'billing_company', sanitize_text_field( $_POST['billing_company'] ) ); } if ( isset( $_POST['billing_address_1'] ) ) { // WooCommerce billing address update_user_meta( $customer_id, 'billing_address_1', sanitize_text_field( $_POST['billing_address_1'] ) ); } if ( isset( $_POST['billing_postcode'] ) ) { // WooCommerce billing phone update_user_meta( $customer_id, 'billing_postcode', sanitize_text_field( $_POST['billing_postcode'] ) ); } if ( isset( $_POST['billing_city'] ) ) { // WooCommerce billing city update_user_meta( $customer_id, 'billing_city', sanitize_text_field( $_POST['billing_city'] ) ); } if ( isset( $_POST['billing_nip'] ) ) { // WooCommerce billing nip update_user_meta( $customer_id, 'billing_nip', sanitize_text_field( $_POST['billing_nip'] ) ); } } add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' ); /** *Displaying new nip field in the backend ** */ add_action( 'show_user_profile', 'ws_update_user_profile' ); add_action( 'edit_user_profile', 'ws_update_user_profile' ); function ws_update_user_profile( $user ){ ?>

Dane Firmy

id, 'Nip' ); echo 'NIP: '.$key_1_values[0]; } /** * Add the field to order emails **/ add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys'); function my_custom_checkout_field_order_meta_keys( $keys ) { $keys[] = 'Nip'; return $keys; }