I customized the woocomerce default address fields. I made the Address1 and city fields select. When I was editing my account and checkout while input, the saved data was coming, now I can’t get it since I made a select.
Fields save data seamlessly. When editing My Account>Address>Address, these fields appear empty when the first page is loaded. Same thing at checkout. When registered customers have registered address data.
// Checkout field update güncelle
function custom_override_checkout_fields_plugin( $fields ) {
global $tr_cities;
$fields['shipping']['shipping_state']['type'] = 'select';
$fields['shipping']['shipping_state']['options'] = array_merge( array( '' => 'Bir seçenek belirleyin...' ), $tr_cities );
$fields['shipping']['shipping_state']['class'] = array('form-row-wide', 'address-field', 'update_totals_on_change', 'validate-required', 'state_select');
$fields['shipping']['shipping_city']['type'] = 'select';
$fields['shipping']['shipping_city']['options'] = array('' => 'Önce il seçin...');
$fields['shipping']['shipping_city']['class'] = array('form-row-wide', 'address-field', 'update_totals_on_change', 'validate-required', 'city_select');
$fields['shipping']['shipping_address_1']['type'] = 'select';
$fields['shipping']['shipping_address_1']['options'] = array('' => 'Önce ilçe seçin...');
$fields['shipping']['shipping_address_1']['class'] = array('form-row-wide', 'address-field', 'update_totals_on_change', 'validate-required', 'address_select');
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields_plugin' );
// My Account field update
function custom_override_my_account_fields_plugin( $address ) {
global $tr_cities;
$address['state']['type'] = 'select';
$address['state']['options'] = array_merge( array( '' => 'Bir seçenek belirleyin...' ), $tr_cities );
$address['state']['class'] = array('form-row-wide', 'address-field', 'update_totals_on_change', 'validate-required', 'state_select');
$address['city']['type'] = 'select';
$address['city']['options'] = array('' => 'Önce il seçin...');
$address['city']['class'] = array('form-row-wide', 'address-field', 'update_totals_on_change', 'validate-required', 'city_select');
$address['address_1']['type'] = 'select';
$address['address_1']['options'] = array('' => 'Önce ilçe seçin...');
$address['address_1']['class'] = array('form-row-wide', 'address-field', 'update_totals_on_change', 'validate-required', 'address_select');
return $address;
}
add_filter( 'woocommerce_default_address_fields', 'custom_override_my_account_fields_plugin' );
I want to show the data in this select field selectively when the first page is loaded.
Poyraz Uluhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.