Okay
  Public Ticket #3515725
registration field visibility
Closed

Comments

  •  3
    cinzia started the conversation

    I created the field CODICE UNIVOCO which should only be visible when selecting ITALY, but it's visible when selecting any country

    I attach the settings for the field: campo-1.png and campo-2.png

    thank you very much and have a nice day

    Attached files:  1.png
      grecia.png
      campo-1.png
      campo-2.png

  •  1,904
    WebWizards replied

    Hi there,

    Is it possible to send me a link to your registration page?

    It would help if I could look at the page directly so I can view its code and see what is happening there,


    I wonder if you may have multiple VAT fields there on the page - if so, that could be the issue, as the registration currently only supports 1 VAT field per page.


    Kind regards,

    Stefan

  •  3
    cinzia replied

    yes, i have field PARTITA IVA (VAT)  too.... 

    so it's not possible to have more field of the same type, for example: VAT field required for Italy and another one not required for other countries?

  •   cinzia replied privately
  •  1,904
    WebWizards replied

    Thank you, that seems to be the issue then, that the plugin currently doesn't support multiple VAT fields.

    Please let me check to see if there's a way we can make an update so it supports it - seems that would be quite helpful.

    If not, I will provide a code snippet to make only Italy required,


    Please let me get back to you on this after we've looked into this,

  •  3
    cinzia replied

    I noticed that in the front-end account details there is a display problem: the two VAT number fields and the codice univoco field are displayed regardless of whether it is in Italy or not. However, it works correctly because the VAT number field for Italy is mandatory and validated only for the account based in Italy.

    Attached files:  campi-ita.png

  •  1,904
    WebWizards replied

    Hi again,

    I looked into this - unfortunately it is a bit difficult technically to make our plugin support multiple VAT fields at the moment - many changes are needed to our code.

    However, I worked on a code snippet to help you set the VAT field as only required for Italy.


    To enable this:

    1. In B2BKing -> Registration Fields -> enable only 1 VAT field. Make that field required. Select all countries that should have VAT (including Italy)

    2. Add this PHP code snippet to your site:

    add_action('wp_head', function(){
        ?>
        <script>
            jQuery(document).ready(function(){
                jQuery('.country_to_state').change(function(){
                    let country = jQuery(this).val();
                    if (country !== 'IT'){
                        // remove required
                        setTimeout(function(){
                            jQuery('#b2bking_vat_number_registration_field').removeAttr('required');
                            jQuery('label[for="b2bking_vat_number_registration_field"] .required').css('display','none');
                        }, 25);
                    } else {
                        jQuery('label[for="b2bking_vat_number_registration_field"] .required').css('display','inline-block');
                    }
                });
            });
        </script>
        <?php
    });
    

    The PHP snippet can be added to functions.php, or by following our guide here: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/


  •  3
    cinzia replied

    thank you very much, I solved the VAT number field problem.
    instead, for the Codice Univoco field, is there a way to link the display of the field based on the selected country without necessarily having it linked to a VAT number?

  •  1,904
    WebWizards replied

    Do you mean to hide / show that field on the registration form, depending on which country is selected?


    By default there is no feature for it, but I believe I can adjust the previous code snippet to make it do that. For that, just let me know what countries you'd like it to show for.

  •  3
    cinzia replied

    thanks, I need the Codice Univoco field which is mandatory and visible only for Italy.

    To simplify, I make the VAT number field mandatory for all countries.

  •  1,904
    WebWizards replied

    To set that up, please set the Codice Univoco field as a TEXT type field, and NOT REQUIRED.

    Then add this code snippet to your site:

    add_action('wp_head', function(){
        ?>
        <script>
            jQuery(document).ready(function(){
                jQuery('#b2bking_field_17484').parent().find('label').append('<span class="required">*</span>');
                showhidefield();
                jQuery('.country_to_state').change(function(){
                    showhidefield();
                });
            });
            function showhidefield(){
                setTimeout(function(){
                    let country = jQuery('.country_to_state').val();
                    if (country !== 'IT'){
                        // hide
                        jQuery('#b2bking_field_17484').parent().parent().css('display','none');
                        jQuery('#b2bking_field_17484').removeAttr('required');
                    } else {
                        jQuery('#b2bking_field_17484').parent().parent().css('display','block');
                        jQuery('#b2bking_field_17484').prop('required', true);
                    }
                }, 50);
                
            }
        </script>
        <?php
    });
    

    It should make it show only for Italy, as required. For other countries it would be hidden.

  •  3
    cinzia replied

    thankyou for all

    it works  if I select "none" in the WooCommerce Billing Field Connection field

    but it only works in the registration form, in edit account it is always visible and not mandatory


  •  1,904
    WebWizards replied

    Is that on the my account page -> account details tab?

    There we do not have the country, so I don't think we have a way to make that work there. For that area, I can only suggest setting the field as "non-editable", so it can no longer be edited after the initial registration:

    https://prnt.sc/IrBFp3kdAohu



  •  3
    cinzia replied

    As soon as the payment page opens, the Codice Univoco field is visible.

    then the operation is correct: if I select Private Customer (B2C), the field disappears; while it appears when I select Business Customer (B2B).

    Attached files:  cu.png

  •  1,904
    WebWizards replied

    Thank you for clarifying,

    Please try changing the snippet to:

    add_action('wp_head', function(){
        ?>
        <script>
            jQuery(document).ready(function(){
                jQuery('#b2bking_field_17484').parent().find('label').append('<span class="required">*</span>');
                showhidefield();
                jQuery('.country_to_state').change(function(){
                    showhidefield();
                });
                setTimeout(function(){
                    showhidefield();
                }, 250);
                setTimeout(function(){
                    showhidefield();
                }, 1500);
            });
            function showhidefield(){
                setTimeout(function(){
                    let country = jQuery('.country_to_state').val();
                    if (country !== 'IT'){
                        // hide
                        jQuery('#b2bking_field_17484').parent().parent().css('display','none');
                        jQuery('#b2bking_field_17484').removeAttr('required');
                    } else {
                        jQuery('#b2bking_field_17484').parent().parent().css('display','block');
                        jQuery('#b2bking_field_17484').prop('required', true);
                    }
                }, 50);
                
            }
        </script>
        <?php
    });
    

    I made a change that I think can help.


    It would also be important to make sure to clear all site caches. When I go to https://staging3.gioielloliquido.com/pagamento/ I do not see the field so I wonder whether this could be related to a caching problem. I'd suggest trying to see if it works for you with a new browser.

  •  3
    cinzia replied

    I use chrome-guest user and also firefox, clear caches, but the problem is always there.

  •   cinzia replied privately
  •  1,904
    WebWizards replied

    Thank you for the details,


    I tested this now as a logged out user but I cannot see the issue at the moment. I did not make any site changes.

    This is what I am seeing: 

    https://www.loom.com/share/8fd55a1e05fd414c80aec97b1e251e4c?sid=be3463d5-338b-4aa0-9088-98c0644ae938

    I started with a new browser (incognito) and added a product to cart then went to checkout.


    Are you still seeing the problem? If so, do you know what I am doing different on my end? Thank you.

  •  3
    cinzia replied

    It's a mistery! I do the same things. The only difference is that I'm in Italy...

    https://www.loom.com/share/f9be492971004c18a3a1411d26463189?sid=61c20ff1-4d64-4253-9cce-8b5852ea10b0


    thanks for your patience :-)

  •  1,904
    WebWizards replied

    You are right, that was the difference : ) 

    I think I have solved it - I modified the snippet in the functions.php file.


    Let me know if you still see an issue please,

  •  3
    cinzia replied

    BINGO! SOLVED!!!! :-)

    Thankyou!!!! :-))))))