Thanks to the help I received in my previous question, I was able to change the HTML of shipping service from radios to a select field. This was done, as suggested, by means of a custom module implementing hook_form_alter
.
function MYMODULE_form_alter(&$form, &$form_state, $form_id){
if ($form_id=='commerce_checkout_form_checkout') {
$form['commerce_shipping']['shipping_service']['#type']='select';
}
}
Now what i need is to have an empty option ("select the proper value") in it, so that the user would be forced to actively choose one of the shipping methods. What I get from
print_r($form);
is
[shipping_service] => Array
(
[#type] => radios
[#options] => Array
(
[deli] => Delivery : 5,00
[pickup] => Pickup: 0,00
)
[#ajax] => Array
(
[callback] => commerce_shipping_pane_service_details_refresh
[wrapper] => commerce-shipping-service-details
)
[deli] => Array
(
[#description] =>
)
[pickup] => Array
(
[#description] =>
)
[#default_value] => deli
)
[service_details] => Array
(
[#type] => container
[#prefix] =>
[#suffix] =>
)
I tried to tinker with dafault value, inserting another option, like
$form['commerce_shipping']['shipping_service']['#options']['_none']='['-select-']';
$form['commerce_shipping']['shipping_service']['#options']['#default_value']='['_none']';
(which was somewhat randomly inspired by the 'print_r' output from a taxonomy term field on the same form but brought no results and did cause AJAX errors. Any ideas?
unset
default value?unset($form['commerce_payment']['payment_method']['#default_value']);
which does not bring the desired result - actually, it does not change anything.$form['commerce_shipping']['shipping_service']['#options']['#default_value']='['_none']';
. The value is then'_none'
, not'[_none]'
.$form['commerce_shipping']['shipping_service']['#options']['#default_value']=['none']
?