WooCommerce – Shipping cost based on selected city


I have added some targeted city myself using a hook on the checkout page. Now I want to change shipping costs on the checkout page based on the selected city. How can I achieve this?

add_filter( 'woocommerce_default_address_fields' , 'cass_address_field_dropdown' );

function cass_address_field_dropdown( $address_fields ) {

    $location_array = array(
'(CUM) Miravalles' => '(CUM) Miravalles',
'(CUM) Cumbayá' => '(CUM) Cumbayá',
'(CUM) Tumbaco' => '(CUM) Tumbaco',
'(CUM) Puembo' => '(CUM) Puembo',
'(CUM) Pifo' => '(CUM) Pifo',
'(CUM) Otros' => '(CUM) Otros',
'(UIO) Quito Centro' => '(UIO) Quito Centro',
'(UIO) Quito Centro-Norte' => '(UIO) Quito Centro-Norte',
'(UIO) Quito Norte' => '(UIO) Quito Norte',
'(UIO) Otros' => '(UIO) Otros',

$address_fields['city']['label'] = 'Location';
$address_fields['city']['type'] = 'select';
$address_fields['city']['options'] = $location_array;

return $address_fields;

, Abdullah Al Faruk 11 months 2020-04-19T04:11:00-05:00 0 Answers 76 views 0

Leave an answer