Support » Plugin: WooCommerce » want addition in checkout fields

  • Hello WooCommerce Forum,
    actually I need help regarding adding a shortcode of the city in the checkout field, have the file of all the shortcode of the city of my country.but don’t know where to put these files exactly.
    can anyone guide me

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    If I understand correctly, are you looking for something like this?

    // Change "city" checkout billing and shipping fields to a dropdown
    add_filter( 'woocommerce_checkout_fields' , 'override_checkout_city_fields' );
    function override_checkout_city_fields( $fields ) {
    
        // Define here in the array your desired cities (Here an example of cities)
        $option_cities = array(
             '' => __( 'Select your city' ),
            'Karachi' => 'Karachi',
            'Lahore' => 'Lahore',
            'Faisalabad' => 'Faisalabad',
            'Rawalpindi' => 'Rawalpindi',
            'Gujranwala' => 'Gujranwala',
            'Peshawar' => 'Peshawar',
            'Multan' => 'Multan',
            'Hyderabad' => 'Hyderabad',
            'Islamabad' => 'Islamabad'
        );
    
        $fields['billing']['billing_city']['type'] = 'select';
        $fields['billing']['billing_city']['options'] = $option_cities;
        $fields['shipping']['shipping_city']['type'] = 'select';
        $fields['shipping']['shipping_city']['options'] = $option_cities;
    
        return $fields;
    }

    Yes I have the code but don’t know where I need to put these code

    <?php

    /* cities prefix conditions ” it is copied from your old plugin. need to convert in switch case” */

    if(empty(ucfirst($order->billing_city))){

    if(ucfirst($order->billing_city) == ‘Karachi’){

    $city = ‘KHI’;

    }else if(ucfirst($order->billing_city) == ‘Abdul Hakeem’){

    $city = ‘AKM’;

    }else if(ucfirst($order->billing_city) == ‘Abottabad’){

    $city = ‘ABT’;

    }else if(ucfirst($order->billing_city) == ‘Ahmedpur East’){

    $city = ‘APE’;

    }else if(ucfirst($order->billing_city) == ‘Ahmedpur Lamma’){

    $city = ‘APL’;

    }else if(ucfirst($order->billing_city) == ‘Akora Khattak’){

    $city = ‘AKK’;

    }else if(ucfirst($order->billing_city) == ‘Alipur’){

    $city = ‘APR’;

    }else if(ucfirst($order->billing_city) == ‘Alipur chatta’){

    $city = ‘APC’;

    }else if(ucfirst($order->billing_city) == ‘Aman Garh’){

    $city = ‘AMR’;
    }

    }

    ?>

    How to Update Code Snippet in functions.php file on your WordPress/WooCommerce site?

    I did the same setup but nothing gonna work.
    let me explain you want i want
    actually I want to keep the city field same but also want to add the city shortcode in next field if someone select city ‘Lahore’ then automatically selects “LHR” in city shortcode field.
    i put the code into the function.php file but nothing happen

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.