I'd like some help with the following:
So we've implemented a custom form as there are various fields that are needed to be captured however we're looking at ways to better handle user error with the following:
When a person enters their Estate name it should autofill certain fields such as the Postal Code and another drop down it should select a certain suburb.
Even if the case is a matter of if's and else ifs it would work but how do we set the fields in.
The idea I think would be to use JS to grab the ID and setting the value accordingly.
Something in JS like
<script type="text/JavaScript">
function onChangeFunc(){
var estate_name = document.getElementById('billing_selections').value;
var suburb = document.getElementById('billing_suburb');
if estate_name == 'funplace' {
document.getElementById("billing_suburb").value = suburb.options[complex_name.selectedIndex].text;
document.getElementById('billing_postcode').value = 10120;
}
}
However how does one do that with the php field
$fields['billing_selections'] = array(
'label' => __('Complex Selection', 'woocommerce'), // Add custom field label
'placeholder' => _x('Complex Selection', 'placeholder', 'woocommerce'), // Add custom field placeholder
'required' => false, // if field is required or not
'clear' => false, // add clear or not
'type' => 'select',
'options' => array(
'' => 'Please select',
'funplace' => 'Fun Place',
),
'class' => array('my-css'),
'priority' => 9,//
);
So a selection in the complex name will then fill Postal Code, City, and a value from a drop downs of Suburbs.