If you need to make the city field a required field in the shipping calculator, you can use the following code snippet to customize the shipping calculator fields. Before you implement this code, you should edit the /wp-content/plugins/woocommerce/templates/cart/shipping-calculator.php file and add this code at line 78. Once you’ve made the changes, save the template file.
<p class="form-row form-row-wide" id="calc_shipping_city_field"> <label for="calc_shipping_city" class="screen-reader-text">City:</label> <input type="text" class="input-text" required value="CurrentShippingCity" placeholder="City" name="calc_shipping_city" id="calc_shipping_city" /> </p>
Output
The below output shows that the city input field is required in the WooCommerce shipping calculator.
Depending on your store’s preference you can choose to make any fields optional or mandatory. Similar to the above customization you can also make fields mandatory or optional on the WooCommerce checkout page.