I am looking for solution for my problems in checkout. First problem is that I need to make field company ID as required if field "Buy as company" is checked. ID of company checkbox is "wi_as_company". I am try to make it like code bellow, but it makes field "billing_company_wi_id" always as required (also for non-company customers).
add_filter( 'woocommerce_checkout_fields' , 'company_checkbox_and_new_checkout_fields_1', 9999 );
function company_checkbox_and_new_checkout_fields_1( $fields ) {
if (isset($_POST['wi_as_company'])) {
$fields['billing']['billing_company_wi_id']['required'] = false;
} else {
$fields['billing']['billing_company_wi_id']['required'] = true;
}
return $fields;
}
My second problem is that I want to move data (first 8 numbers) automatically from one field to another one and add 2 letters before. One field have this format:
12345678-Y-YY
and I want to move first 8 characters to another field like this:
XX12345678
I will be very grateful for any suggestions.
2
Answers
ANSWER FOR FIRST PROBLEM: If checkbox is checked, then field company ID is required. Write code bellow to your child themes functions.php file and change ID of elements: wi_as_company is ID of checkbox and billing_company_wi_id is ID of required field if checkbox is checked
ANSWER FOR SECOND PROBLEM: Change in code ID of fields and number of characters to copy. In this case it will copy first 8 characters from "billing_company_wi_tax" to "billing_company_wi_vat" plus it will add letters "XX" before copied text. Insert this function to your child themes functions.php.