Is it possible to create different registration fields for different languages? I'm using WPML.
If i disable registration field on another language it still appears in all languages. I know that is the way to translate registration fields according to the documentation but what about showing specific field only in one language?
I've thought about this and looked into the code - it's not possible right now with the way our plugin works. We would need to extend the functionality so that the plugin can understand what language is currently selected with WPML. We can look at an improvement here for future updates, but right now I don't see a way to do it.
That being said, I'm pretty handy with JavaScript. If you give me a link to your registration page and tell me which fields need to be hidden for which language, I can send you a JS snippet to add to your site to handle it for that specific page.
For now I only have the site only on my local development environment. Can you provide a little example for example as a pseudo code so I could try to do it myself?
So my goal is to show one specific field for one specific language. All the other fields are same in all languages. That field should also be required for that language so just hiding it for other languages wouldn't work. I could mark it as required with javascript (and not in the backend) but is there some better way to achieve the funcionality?
Ideally, only enabled fields would show in their own specific languages. But unfortunately that requires some major overhauls to our code in many places. So at the moment, I think setting it up with JS is the easiest way to do it.
I have written some code below that hopefully can help and makes sense. Required can be added / removed with JavaScript, so we can fully control it that way as well.
jQuery(document).ready(function(){
// run function when page loads
setTimeout(function(){
showHideRegistrationFieldsCustom();
}, 250);
// run function everytime fields are shown/hidden
jQuery('#b2bking_registration_roles_dropdown').change(showHideRegistrationFieldsCustom);
jQuery('.b2bking_country_field_selector select').change(showHideRegistrationFieldsCustom);
jQuery('select#billing_country').change(showHideRegistrationFieldsCustom);
function showHideRegistrationFieldsCustom(){
// set timeout so that function runs after regular plugin js functions
setTimeout(function(){
// get current WPML language
var selectedLang = b2bking_display_settings.purchase_lists_language_option;
// get field and container
var fieldInput = jQuery('input[name=b2bking_custom_field_7381]');
var fieldContainer = jQuery('input[name=b2bking_custom_field_7381]').parent().parent();
if (selectedLang === 'English'){
// show english specific field and make it required
jQuery(fieldContainer).css('display','block');
jQuery(fieldInput).prop('required','true');
} else {
// hide english specific field and remove required
jQuery(fieldContainer).css('display','none');
jQuery(fieldInput).removeAttr('required');
}
}, 250);
}
});
In the above code, I think the only thing that needs to be changed is the field name
b2bking_custom_field_7381
and the language
However I haven't had a chance to test it with WPML.
Would it be also possible to select default country for specific language? I use the Country + State field and it would be great if it the country is selected automatically by chosen language.
This is almost what I need. Only problem is that the state field is not hiding like it normally would if I clicked Finland manually from the select field. Can it also be hidden in a way that it is still possible to pick some other country that has the state field?
Hi,
Is it possible to create different registration fields for different languages? I'm using WPML.
If i disable registration field on another language it still appears in all languages. I know that is the way to translate registration fields according to the documentation but what about showing specific field only in one language?
Hi Erkko,
I've thought about this and looked into the code - it's not possible right now with the way our plugin works. We would need to extend the functionality so that the plugin can understand what language is currently selected with WPML. We can look at an improvement here for future updates, but right now I don't see a way to do it.
That being said, I'm pretty handy with JavaScript. If you give me a link to your registration page and tell me which fields need to be hidden for which language, I can send you a JS snippet to add to your site to handle it for that specific page.
Kind regards,
Stefan
For now I only have the site only on my local development environment. Can you provide a little example for example as a pseudo code so I could try to do it myself?
So my goal is to show one specific field for one specific language. All the other fields are same in all languages. That field should also be required for that language so just hiding it for other languages wouldn't work. I could mark it as required with javascript (and not in the backend) but is there some better way to achieve the funcionality?
Ideally, only enabled fields would show in their own specific languages. But unfortunately that requires some major overhauls to our code in many places. So at the moment, I think setting it up with JS is the easiest way to do it.
I have written some code below that hopefully can help and makes sense. Required can be added / removed with JavaScript, so we can fully control it that way as well.
In the above code, I think the only thing that needs to be changed is the field name
and the language
However I haven't had a chance to test it with WPML.
Kind regards,
Stefan
Thank you! This solution worked for me.
Would it be also possible to select default country for specific language? I use the Country + State field and it would be great if it the country is selected automatically by chosen language.
Glad that worked!
Yes, it can be done.
Here is the code:
Kind regards,
Stefan
This is almost what I need. Only problem is that the state field is not hiding like it normally would if I clicked Finland manually from the select field. Can it also be hidden in a way that it is still possible to pick some other country that has the state field?
I think the following should do it:
You can see I added a line of code to the Finnish bracket to hide the state.