Advertisement
Fany_VanDaal

Registrační formulář s IČ/DIČ

Jan 24th, 2022
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.57 KB | None | 0 0
  1. // úprava registračního formuláře
  2. // spolupracuje s https://cs.wordpress.org/plugins/woolab-ic-dic/
  3. function wooc_extra_register_fields() {
  4. ?>
  5. <strong>Vytvoření účtu neopravňuje k nákupu. Registrace nového účtu podléhá ručnímu schválení, o čemž budete informováni po kontrole údajů emailem.<br />Velkobchod VeloStore není určen pro soukromé osoby.</strong><br />Položky označené * jsou povinné.<br /><br />
  6.        <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
  7.        <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
  8.        <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
  9.        <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
  10. <div class="clear"></div>
  11.        <label for="reg_billing_company"><?php _e( 'Název firmy, skupiny, spolku, klubu, nadace...', 'woocommerce' ); ?><span class="required">*</span></label>
  12.        <input type="text" class="input-text" name="billing_company" id="reg_billing_company" value="<?php if ( ! empty( $_POST['billing_company'] ) ) esc_attr_e( $_POST['billing_company'] ); ?>" />
  13.        <label for="reg_billing_ic"><?php _e( 'IČ', 'woocommerce' ); ?></label>
  14.        <input type="text" class="input-text" name="billing_ic" id="reg_billing_ic" value="<?php if ( ! empty( $_POST['billing_ic'] ) ) esc_attr_e( $_POST['billing_ic'] ); ?>" />
  15.        <label for="reg_billing_dic"><?php _e( 'DIČ', 'woocommerce' ); ?></label>
  16.        <input type="text" class="input-text" name="billing_dic" id="reg_billing_dic" value="<?php if ( ! empty( $_POST['billing_dic'] ) ) esc_attr_e( $_POST['billing_dic'] ); ?>" />
  17. <div class="clear"></div>
  18.        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>
  19.        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />
  20.        <label for="reg_billing_address_1"><?php _e( 'Address', 'woocommerce' ); ?><span class="required">*</span></label>
  21.        <input type="text" class="input-text" name="billing_address_1" id="reg_billing_address_1" value="<?php if ( ! empty( $_POST['billing_address_1'] ) ) esc_attr_e( $_POST['billing_address_1'] ); ?>" />
  22.        <label for="reg_billing_city"><?php _e( 'City', 'woocommerce' ); ?><span class="required">*</span></label>
  23.        <input type="text" class="input-text" name="billing_city" id="reg_billing_city" value="<?php if ( ! empty( $_POST['billing_city'] ) ) esc_attr_e( $_POST['billing_city'] ); ?>" />
  24.        <label for="reg_billing_postcode"><?php _e( 'ZIP', 'woocommerce' ); ?><span class="required">*</span></label>
  25.        <input type="text" class="input-text" name="billing_postcode" id="reg_billing_postcode" value="<?php if ( ! empty( $_POST['billing_postcode'] ) ) esc_attr_e( $_POST['billing_postcode'] ); ?>" />
  26. <div class="clear"></div>
  27.        <?php
  28. }
  29. add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
  30.  
  31. // kontrola údajů
  32. function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
  33.        if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
  34.               $validation_errors->add( 'billing_first_name_error', __( 'Jméno je povinná položka!', 'woocommerce' ) );
  35.        }
  36.        if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
  37.               $validation_errors->add( 'billing_last_name_error', __( 'Příjmení je povinná položka!.', 'woocommerce' ) );
  38.        }
  39.        if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
  40.               $validation_errors->add( 'billing_phone_error', __( 'Telefon je povinná položka!.', 'woocommerce' ) );
  41.        }
  42.        if ( isset( $_POST['billing_address_1'] ) && empty( $_POST['billing_address_1'] ) ) {
  43.               $validation_errors->add( 'billing_address_1_error', __( 'Adresa je povinná položka!.', 'woocommerce' ) );
  44.        }
  45.        if ( isset( $_POST['billing_city'] ) && empty( $_POST['billing_city'] ) ) {
  46.               $validation_errors->add( 'billing_city_error', __( 'Město je povinná položka!.', 'woocommerce' ) );
  47.        }
  48.        if ( isset( $_POST['billing_postcode'] ) && empty( $_POST['billing_postcode'] ) ) {
  49.               $validation_errors->add( 'billing_postcode_error', __( 'PSČ je povinná položka!.', 'woocommerce' ) );
  50.        }
  51.        if ( isset( $_POST['billing_company'] ) && empty( $_POST['billing_company'] ) ) {
  52.               $validation_errors->add( 'billing_company_error', __( 'Název firmy, spolku atd je povinná položka!.', 'woocommerce' ) );
  53.        }   
  54. }
  55. add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
  56.  
  57. // uložení údajů zákazníka do databáze
  58. function wooc_save_extra_register_fields( $customer_id ) {
  59.        if ( isset( $_POST['billing_first_name'] ) ) {
  60.               // WordPress default first name field.
  61.               update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
  62.               // WooCommerce billing first name.
  63.               update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
  64.        }
  65.        if ( isset( $_POST['billing_last_name'] ) ) {
  66.               // aktualizujeme Jméno
  67.               update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
  68.               // aktualizujeme Příjmení
  69.               update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
  70.        }
  71.        if ( isset( $_POST['billing_phone'] ) ) {
  72.               // aktualizujeme Telefon
  73.               update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
  74.        }
  75.        if ( isset( $_POST['billing_address_1'] ) ) {
  76.               // aktualizujeme Adresu/ulici
  77.               update_user_meta( $customer_id, 'billing_address_1', sanitize_text_field( $_POST['billing_address_1'] ) );
  78.        }
  79.        if ( isset( $_POST['billing_city'] ) ) {
  80.               // aktualizujeme Město
  81.               update_user_meta( $customer_id, 'billing_city', sanitize_text_field( $_POST['billing_city'] ) );
  82.        }
  83.        if ( isset( $_POST['billing_postcode'] ) ) {
  84.               // aktualizujeme PSČ
  85.               update_user_meta( $customer_id, 'billing_postcode', sanitize_text_field( $_POST['billing_postcode'] ) );
  86.        }
  87.        if ( isset( $_POST['billing_company'] ) ) {
  88.               // aktualizujeme název firmy
  89.               update_user_meta( $customer_id, 'billing_company', sanitize_text_field( $_POST['billing_company'] ) );
  90.        }
  91.        if ( isset( $_POST['billing_ic'] ) ) {
  92.               // aktualizujeme IČ
  93.               update_user_meta( $customer_id, 'billing_ic', sanitize_text_field( $_POST['billing_ic'] ) );
  94.        }
  95.        if ( isset( $_POST['billing_dic'] ) ) {
  96.               // aktualizujeme DIČ
  97.               update_user_meta( $customer_id, 'billing_dic', sanitize_text_field( $_POST['billing_dic'] ) );
  98.        }                                        
  99. }
  100. add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement