Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ověřování IČO/VIES v můj účet #19

Open
vyskoczilova opened this issue Sep 26, 2019 · 4 comments
Open

Ověřování IČO/VIES v můj účet #19

vyskoczilova opened this issue Sep 26, 2019 · 4 comments
Milestone

Comments

@vyskoczilova
Copy link
Owner

https://wordpress.org/support/topic/overovani-ico-v-ares-muj-ucet/#post-11970952

@vyskoczilova vyskoczilova added this to the 2.1.0 milestone Apr 7, 2020
@Aramon
Copy link

Aramon commented Sep 5, 2021

Upravil jsem si registrační formulář, protože jsme velkoobchod, tak, aby se zadávalo i IČ a DIČ. Hodně by se mi hodila možnost ověřovat tyto údaje už při registraci/vytváření účtu. Plánujete to?

@vyskoczilova
Copy link
Owner Author

@Aramon Dobrý den, nechcete úpravu registračního formuláře pushnout jako změnu, že bychom pak přidali ověření při registraci? Předpokládám, že asi používáte standardní WooCommerce registrační formulář, že?

@Aramon
Copy link

Aramon commented Sep 13, 2021

Používám tuto úpravu, vyplnění IČ/DIČ není povinné. Určitě by bylo zajímavé mít možnost zaškrtnout Registrace na firmu a pak by IČ mělo být povinné. A úplně ideální možnost nastavit "firemním" zákazníkům nějakou jinou roli než zákazník:

// úprava registračního formuláře
function wooc_extra_register_fields() {
?>
<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 />
       <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
       <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
<div class="clear"></div>
       <label for="reg_billing_company"><?php _e( 'Název firmy, skupiny, spolku, klubu, nadace...', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
       <label for="reg_billing_ic"><?php _e( 'IČ', 'woocommerce' ); ?></label>
       <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'] ); ?>" />
       <label for="reg_billing_dic"><?php _e( 'DIČ', 'woocommerce' ); ?></label>
       <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'] ); ?>" />
<div class="clear"></div>
       <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
       <label for="reg_billing_address_1"><?php _e( 'Address', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
       <label for="reg_billing_city"><?php _e( 'City', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
       <label for="reg_billing_postcode"><?php _e( 'ZIP', 'woocommerce' ); ?><span class="required">*</span></label>
       <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'] ); ?>" />
<div class="clear"></div>
       <?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );

// kontrola údajů
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
       if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
              $validation_errors->add( 'billing_first_name_error', __( 'Jméno je povinná položka!', 'woocommerce' ) );
       }
       if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
              $validation_errors->add( 'billing_last_name_error', __( 'Příjmení je povinná položka!.', 'woocommerce' ) );
       }
       if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
              $validation_errors->add( 'billing_phone_error', __( 'Telefon je povinná položka!.', 'woocommerce' ) );
       }
       if ( isset( $_POST['billing_address_1'] ) && empty( $_POST['billing_address_1'] ) ) {
              $validation_errors->add( 'billing_address_1_error', __( 'Adresa je povinná položka!.', 'woocommerce' ) );
       }
       if ( isset( $_POST['billing_city'] ) && empty( $_POST['billing_city'] ) ) {
              $validation_errors->add( 'billing_city_error', __( 'Město je povinná položka!.', 'woocommerce' ) );
       }
       if ( isset( $_POST['billing_postcode'] ) && empty( $_POST['billing_postcode'] ) ) {
              $validation_errors->add( 'billing_postcode_error', __( 'PSČ je povinná položka!.', 'woocommerce' ) );
       }
       if ( isset( $_POST['billing_company'] ) && empty( $_POST['billing_company'] ) ) {
              $validation_errors->add( 'billing_company_error', __( 'Název firmy, spolku atd je povinná položka!.', 'woocommerce' ) );
       }	
}
add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );

// uložení údajů zákazníka do databáze
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'] ) ) {
              // aktualizujeme Jméno
              update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
              // aktualizujeme Příjmení
              update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
       }
       if ( isset( $_POST['billing_phone'] ) ) {
              // aktualizujeme Telefon
              update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
       }
       if ( isset( $_POST['billing_address_1'] ) ) {
              // aktualizujeme Adresu/ulici
              update_user_meta( $customer_id, 'billing_address_1', sanitize_text_field( $_POST['billing_address_1'] ) );
       }
       if ( isset( $_POST['billing_city'] ) ) {
              // aktualizujeme Město
              update_user_meta( $customer_id, 'billing_city', sanitize_text_field( $_POST['billing_city'] ) );
       }
       if ( isset( $_POST['billing_postcode'] ) ) {
              // aktualizujeme PSČ
              update_user_meta( $customer_id, 'billing_postcode', sanitize_text_field( $_POST['billing_postcode'] ) );
       } 
       if ( isset( $_POST['billing_company'] ) ) {
              // aktualizujeme název firmy
              update_user_meta( $customer_id, 'billing_company', sanitize_text_field( $_POST['billing_company'] ) );
       }
       if ( isset( $_POST['billing_ic'] ) ) {
              // aktualizujeme IČ
              update_user_meta( $customer_id, 'billing_ic', sanitize_text_field( $_POST['billing_ic'] ) );
       }
       if ( isset( $_POST['billing_dic'] ) ) {
              // aktualizujeme DIČ
              update_user_meta( $customer_id, 'billing_dic', sanitize_text_field( $_POST['billing_dic'] ) );
       }                                         
}
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

@vyskoczilova
Copy link
Owner Author

vyskoczilova commented Sep 16, 2021

@Aramon Díky! Bude to potřeba trochu uhladit, ale každopádně, pokud chcete validovat data, tak můžete:

DIČ (logika podrobně zde - asi chcete kontrolovat ještě zemi)

$validator = new Ibericode\Vat\Validator();
if ( ! $validator->validateVatNumberFormat( $dic )) {
   // vyhodit hlášku
}

A stejně tak můžete otestovat IČO vůči Aresu woolab_icdic_ares( $ico ); pokud je české

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants