Answer the question
In order to leave comments, you need to log in
How to make country and city fields in woocomerce via select?
billing_country I get only through text input. But shipping_country is displayed by the select. But I need to change the first field in select. Please help
me here is the code I am using
<?php
/**
Remove all possible fields
**/
function wc_remove_checkout_fields( $fields ) {
// Billing fields
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_email'] );
unset( $fields['billing']['billing_phone'] );
unset( $fields['billing']['billing_state'] );
unset( $fields['billing']['billing_first_name'] );
unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_city'] );
unset( $fields['billing']['billing_postcode'] );
// Order fields
unset( $fields['order']['order_comments'] );
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'wc_remove_checkout_fields' );
function first_checkout_fields($fields)
{
$fields['billing']['billing_first_name']['placeholder'] = 'First Name';
$fields['billing']['billing_last_name']['placeholder'] = 'Last Name';
$fields['billing']['billing_phone']['placeholder'] = 'Phone';
$fields['billing']['billing_email']['placeholder'] = 'E-mail';
$fields['billing']['billing_postcode']['placeholder'] = 'Postcode';
return $fields;
}
add_filter('woocommerce_checkout_fields', 'first_checkout_fields');
add_filter( 'woocommerce_checkout_fields', 'wpbl_move_to_order_group' );
function wpbl_move_to_order_group( $array ){
$array['order']['billing_company'] = $array['billing']['billing_company'];
$array['order']['billing_state'] = $array['billing']['billing_state'];
$array['order']['billing_country'] = $array['billing']['billing_country'];
$array['order']['billing_city'] = $array['billing']['billing_city'];
$array['order']['billing_address_1'] = $array['billing']['billing_address_1'];
$array['order']['billing_company']['placeholder'] = 'Name Company (not necessary)';
$array['order']['billing_state']['placeholder'] = 'Region / State';
$array['order']['billing_country']['placeholder'] = 'Country';
$array['order']['billing_city']['placeholder'] = 'City';
$array['order']['billing_address_1']['placeholder'] = 'Address';
return $array;
}
add_filter( 'woocommerce_checkout_fields', 'add_custom_select_country' );
function add_custom_select_country( $fields ) {
$fields['billing']['billing_country'] = array(
'type' => 'select',
'required' => true,
)
);
return $fields;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question