Case 1: Make checkout field read only
If you are using the WooCommerce Checkout Field Editor Pro plugin, we can save additional field values as user meta. From next time, these fields are autofill with saved user data.
If you plan to disallow editing of saved user data, you can make these fields read-only after confirm that he is a logged-in user.
Use the below code snippet in your themeās or child themeās functions.php file. Update the string {field_name} in the filter tag in the code snippet with your field name.
function thwcfe_login_make_field_readonly($value){
// First confirm that user is already logged in
if(is_user_logged_in()){
$value = true;
}
return $value;
}
add_filter('thwcfe_is_readonly_field_{field_name}', 'thwcfe_login_make_field_readonly');
Case 2: Change the position of a description of the checkout fieldĀ
In WooCommerce Checkout Field Editor Pro, there is an option to add a description for checkout fields. The default position to display the description is below the input field.
In some cases, we need to change this position as per theme style. It may for all fields or some selected fields.
If you like to change the position of the description below label & the above input field, you can use the below code snippet.
Use the below code snippet in your themeās or child themeās functions.php file. Also, update your field name in the code snippet.
function thwcfe_change_position_desc($position, $key){
if($key === 'field_name'){
$position = true;
}
return $position;
}
add_filter('thwcfe_display_field_description_below_label', 'thwcfe_change_position_desc', 10, 2);
Case 3: Set or modify the value of a checkout field
Use the below code snippet in your themeās or child themeās functions.phpĀ file. Update the stringĀ {field_name} in the filter tag in the code snippet with your field name.
function thwcfe_field_value_changer($value){
$value = 'New Value';
return $value ;
}
add_filter('thwcfe_woocommerce_form_field_value_{field_name}', 'thwcfe_field_value_changer');
Note: Using this code, you just change the value of the input field. But users always have the option to update this value of the input field.
Getting Started
Advanced Settings
For Developers
Frequently Asked Questions
Compatible Plugin & Themes
How