Public Ticket #3515725

registration field visibility

Closed
Comments
2,762
KingsPlugins replied 3 years ago on November 6, 2023 at 10:14am

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

8 Tickets 6
cinzia replied 3 years ago on November 6, 2023 at 10:48am

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?

2,762
KingsPlugins replied 3 years ago on November 6, 2023 at 11:53am

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,

1
8 Tickets 6
cinzia replied 3 years ago on November 13, 2023 at 7:46am

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:

2,762
KingsPlugins replied 3 years ago on November 13, 2023 at 8:53am

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://b2bkingplugin.com/docs/how-to-add-a-snippet-php-or-js/

8 Tickets 6
cinzia replied 3 years ago on November 13, 2023 at 1:24pm

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?

2,762
KingsPlugins replied 3 years ago on November 13, 2023 at 10:28pm

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.

8 Tickets 6
cinzia replied 3 years ago on November 14, 2023 at 9:44am

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.

2,762
KingsPlugins replied 3 years ago on November 15, 2023 at 3:27pm

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.

8 Tickets 6
cinzia replied 3 years ago on November 15, 2023 at 8:32pm

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


2,762
KingsPlugins replied 3 years ago on November 17, 2023 at 9:05am

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



8 Tickets 6
cinzia replied 3 years ago on November 25, 2023 at 2:02pm

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:

2,762
KingsPlugins replied 3 years ago on November 29, 2023 at 2:39am

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.

2,762
KingsPlugins replied 3 years ago on December 4, 2023 at 4:25am

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.

2,762
KingsPlugins replied 3 years ago on December 4, 2023 at 1:59pm

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,

Sign In