Advertisement
Guest User

Untitled

a guest
Aug 29th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. /*Add NIP $ REGON to register*/
  2.  
  3. add_action( 'woocommerce_register_form', 'crf_registration_form' );
  4. function crf_registration_form() {
  5.  
  6. $NIP = ! empty( $_POST['NIP'] ) ? intval( $_POST['NIP'] ) : '';
  7. $REGON = ! empty( $_POST['REGON'] ) ? intval( $_POST['REGON'] ) : '';
  8. ?>
  9. <p>
  10. <label for="NIP"><?php esc_html_e( 'NIP*', 'crf' ) ?><br/>
  11. <input type="number"
  12. id="NIP"
  13. name="NIP"
  14. value="<?php echo esc_attr( $NIP ); ?>"
  15. class="input"
  16. />
  17. </label>
  18. <label for="REGON"><?php esc_html_e( 'REGON*', 'crf' ) ?><br/>
  19. <input type="number"
  20. id="REGON"
  21. name="REGON"
  22. value="<?php echo esc_attr( $REGON ); ?>"
  23. class="input"
  24. />
  25. </label>
  26. </p>
  27. <?php
  28. }
  29.  
  30. /*Errors*/
  31. add_filter( 'registration_errors', 'crf_registration_errors', 10, 3 );
  32. function crf_registration_errors( $errors, $sanitized_user_login, $user_email ) {
  33.  
  34. if ( empty( $_POST['NIP'] ) ) {
  35. $errors->add( 'NIP_error', __( '<strong>Błąd</strong>: Proszę wpisać numer NIP', 'crf' ) );
  36. }
  37.  
  38. if ( empty( $_POST['REGON'] ) ) {
  39. $errors->add( 'REGON_error', __( '<strong>Błąd</strong>: Proszę wpisać numer REGON', 'crf' ) );
  40. }
  41.  
  42. return $errors;
  43. }
  44. /*Save NIP & REGON*/
  45. add_action( 'user_register', 'crf_user_register' );
  46. function crf_user_register( $user_id ) {
  47. if ( ! empty( $_POST['NIP'] ) ) {
  48. update_user_meta( $user_id, 'NIP', intval( $_POST['NIP'] ) );
  49. }
  50. if ( ! empty( $_POST['REGON'] ) ) {
  51. update_user_meta( $user_id, 'REGON', intval( $_POST['REGON'] ) );
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement