add_filter: woocommerce_billing_fields
woocommerce_shipping_fields
add_filter( 'woocommerce_billing_fields', 'tzn_custom_billing_title_fields', 99, 99);
function tzn_custom_billing_title_fields( $fields ) {
$fields['billing_title'] = [
'label' => __('Title', 'tzn'), // Add custom field label
'required' => true, // if field is required or not
'clear' => true, // add clear or not
'type' => 'radio', // add field type
'class' => ['title-buttons'],
'priority' => 5,
'options' => [
'1' => __('Mr', 'tzn'),
'2' => __('Ms', 'tzn'),
'3' => __('Divers', 'tzn'),
],
'default' => '1',
'required' => true
];
return $fields;
}
add_filter( 'woocommerce_shipping_fields' , 'default_shipping_address' );
function default_shipping_address( $fields ) {
$fields['shipping_title'] = [
'label' => __('Title', 'tzn'), // Add custom field label
'required' => true, // if field is required or not
'clear' => true, // add clear or not
'type' => 'radio', // add field type
'class' => ['title-buttons'],
'priority' => 5,
'options' => [
'1' => __('Mr', 'tzn'),
'2' => __('Ms', 'tzn'),
'3' => __('Divers', 'tzn'),
],
'default' => '1',
'required' => true
];
return $fields;
}
$('#main .title-buttons.form-row .woocommerce-input-wrapper label').click(function (e) {
e.preventDefault();
var id = $(this).attr('for');
//$('#main .title-buttons .woocommerce-input-wrapper input[checked="checked"]').removeAttr('checked');
//$('#main .title-buttons .woocommerce-input-wrapper input#' + id ).attr( 'checked', 'checked' ).prop('checked', true);
$(this).closest('.woocommerce-input-wrapper').find('input[checked="checked"]').removeAttr('checked');
$(this).closest('.woocommerce-input-wrapper').find( 'input#' + id ).prop( 'checked', true );
if (id == 'billing_title_3') {
$('#billing_company_field').css('display','block');
}else{
$('#billing_company_field').css('display','none');
}
});