Title: Select Options from xml, json, csv
Last modified: August 21, 2016

---

# Select Options from xml, json, csv

 *  Resolved [Brendavo](https://wordpress.org/support/users/successful-life/)
 * (@successful-life)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/select-options-from-xml-json-csv/)
 * Hi,
 * Is it possible to make a select list with options from an API ? Either input 
   directly from an xml, json, csv file or, even better, use a script with a *.js
   url src ?
 * The thing is, in my country we use Post Stations, that are in every Mall or supermarket
   and we ship our packages to those stations, where the client picks them up.
    
   So i made a Select field in the billing checkout section with all the Post Station
   locations. BUT, these locations change a lot, new stations get added every month
   and some get closed or moved.
 * That’s why the Shipping provider has a url with a terminals.js that gets updated
   by them every time they change a location.
 * So how could i add this script in to the Select options ?
 * `<script type="text/javascript" src="http://klients.pastastacija.lv/api/terminals.
   js"></script>`
 * [https://wordpress.org/plugins/woocommerce-poor-guys-swiss-knife/](https://wordpress.org/plugins/woocommerce-poor-guys-swiss-knife/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [ulihake](https://wordpress.org/support/users/ulih/)
 * (@ulih)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/select-options-from-xml-json-csv/#post-4686910)
 * Hello Brendavo.
 * Thanks for your feedback. Please update to 1.8.1 as soon as it will be available
   today.
 * 1. Create a select field. The field will show up and in the field name column
   you find the id of the field, something like billing_postoffices
 * 2. Paste your code into the file wcpgsk_user.js with the internal Code Editor
   of WordPress for plugins or paste your code into the new field in the Checkout
   Section of WCPGSK (the second method is permanent and the code will not be lost
   during updates, whereas the first may offer more stable code handling).
 * 3. Before pasting your code change the following line:
 * `var _postServiceTerminalsSelect = document.getElementById('ps-terminal-slect');`
 * to
 * `var _postServiceTerminalsSelect = document.getElementById('billing_postoffices');`
 * where billing_postoffices should be set to the field name of your select.
 * 4. On the checkout form you should see your select field filled with the post
   offices
 * Regards.
 * uh
 *  Thread Starter [Brendavo](https://wordpress.org/support/users/successful-life/)
 * (@successful-life)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/select-options-from-xml-json-csv/#post-4686990)
 * Hi, thank you very much for the reply.
 * I tried to do what you told me, but for some reason it doesnt work.
 * I created a select field with the id=billing_pastastacija, then changed the var
   to _postServiceTerminalsSelect = document.getElementById(‘billing_pastastacija’);
 * and pasted
    <script type=”text/javascript” src=”[http://klients.pastastacija.lv/api/terminals.js”></script&gt](http://klients.pastastacija.lv/api/terminals.js”></script&gt);
 * in to the select Options box, for the new field.
 * But in the checkout it just shows the script text.
 * Here is how the wcpgsk_user.js file looks like. If i would paste the script into
   the wcpgsk_user.js file, where and how should i do that?
 *     ```
       /*
        * Please paste your custom functions for WooCommerce checkout here
        * You may use this file to run your own client side validation for the checkout form
   
        * Example code to fill a select option:
   
       var _postServiceTerminals = [
       		{id: '1', name: 'Rīga, Pasta Stacija 101, A. Saharova iela 20a (Maxima XX)'},{id: '6', name: 'Rīga, Pasta Stacija 106, Āzenes iela 5 (T/C Olimpia)'},{id: '24', name: 'Rīga, Pasta Stacija 124, Brīvības 434b (T/C Juglas Centrs)'},{id: '39', name: 'Rīga, Pasta Stacija 139, Dzirnavu iela 67 (Galleria Riga)'},{id: '2', name: 'Rīga, Pasta Stacija 102, K. Ulmaņa gatve 88a (Maxima XXX)'},{id: '42', name: 'Rīga, Pasta Stacija 142, Krasta iela 46 (T/C MOLS)'},{id: '29', name: 'Rīga, Pasta Stacija 129, Mūkusalas iela 95 (T/C IKI)'},{id: '40', name: 'Rīga, Pasta Stacija 140, Rīga, Stacijas laukums 2 (T/C Origo)'},{id: '3', name: 'Rīga, Pasta Stacija 103, Slokas iela 115 (Maxima XXX)'},{id: '7', name: 'Rīga, Pasta Stacija 107, Stirnu iela 26'},{id: '15', name: 'Rīga, Pasta Stacija 115, Tilta iela 32 (Rimi)'},{id: '30', name: 'Aizkraukle, Pasta Stacija 130, Spīdolas iela 17 (T/C SuperNetto)'},{id: '27', name: 'Alūksne, Pasta Stacija 127, Pils iela 9b (t/c Maxima)'},{id: '21', name: 'Bauska, Pasta Stacija 121, Pionieru iela 2 (Rimi)'},{id: '31', name: 'Cēsis, Pasta Stacija 131, Lapsu iela 23 (Mego)'},{id: '17', name: 'Daugavpils, Pasta Stacija 117, Rīgas iela 9 (t/c SOLO)'},{id: '26', name: 'Dobele, Pasta Stacija 126, Muldavas iela 3a (T/C Forums)'},{id: '36', name: 'Gulbene, Pasta Stacija 136, Skolas iela 7 (t/c Maxima X)'},{id: '16', name: 'Jēkabpils, Pasta Stacija 116, Vienības iela 1a, T/C "MEGO"'},{id: '8', name: 'Jelgava, Pasta Stacija 108, Katoļu iela 7, (Kanclera nams)'},{id: '20', name: 'Jūrmala, Pasta Stacija 120, Artilērijas iela 2 (IKI)'},{id: '28', name: 'Ķekava, Pasta Stacija 128, Rīgas iela 22 (T/C Liiba)'},{id: '22', name: 'Kuldīga, Pasta Stacija 122, Smilšu iela 20 (ELVI)'},{id: '4', name: 'Liepāja, Pasta Stacija 104, K. Zāles laukums 8 (T/C Ostmala)'},{id: '41', name: 'Liepāja, Pasta Stacija 141, Klaipēdas iela 62 (t/c XL Sala)'},{id: '32', name: 'Limbaži, Pasta Stacija 132, Stacijas iela 8 (T/C Maxima XX)'},{id: '25', name: 'Madona, Pasta Stacija 125, Rūpniecības iela 49 (Maxima XX)'},{id: '18', name: 'Ogre, Pasta Stacija 118, Rīgas iela 23 (T/C Dauga)'},{id: '38', name: 'Preiļi, Pasta Stacija 138, Rēzeknes iela 4a (Maxima X)'},{id: '14', name: 'Rēzekne, Pasta Stacija 114, Pulkveža Brieža iela 26 (Maxima X)'},{id: '5', name: 'Saldus, Pasta Stacija 105, Striķu iela 10c (T/C Akvārijs)'},{id: '12', name: 'Sigulda, Pasta Stacija 112, Vidzemes šoseja 16 (T/C Raibais suns)'},{id: '23', name: 'Talsi, Pasta Stacija 123, Rīgas iela 8 (Maxima XX)'},{id: '19', name: 'Tukums, Pasta Stacija 119, Pasta iela 14 (T/C Rimi)'},{id: '10', name: 'Valka, Pasta Stacija 110, Ausekļa iela 54 (T/C Walk)'},{id: '9', name: 'Valmiera, Pasta Stacija 109, Rīgas iela 4 (T/C Valleta)'},{id: '13', name: 'Ventspils, Pasta Stacija 113, Lielais prospekts 3/5 (T/C Tobago)'}
       	];
   
       	var _postServiceTerminalsSelect = document.getElementById('billing_pastastacija');
       	for (var _ps_index = 0; _ps_index < _postServiceTerminals.length; _ps_index++ ) {
       		var _psTerminal = _postServiceTerminals[_ps_index];
       		var _postServiceOption = document.createElement('option');
       		_postServiceOption.value = _psTerminal.id;
       		_postServiceOption.text = _psTerminal.name;
   
       		try {
       		  _postServiceTerminalsSelect.add(_postServiceOption, _postServiceTerminalsSelect.options[null]);
       		}
       		catch (e)
       		{
       		  _postServiceTerminalsSelect.add(_postServiceOption, null);
       		}
       	}
       */
       ```
   
 *  Plugin Author [ulihake](https://wordpress.org/support/users/ulih/)
 * (@ulih)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/select-options-from-xml-json-csv/#post-4686991)
 * Found this open again. If you have problems with this, please open a new thread.
   
   Thanks. uh

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Select Options from xml, json, csv’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woocommerce-poor-guys-swiss-knife_ffffff.
   svg)
 * [WooCommerce Poor Guys Swiss Knife](https://wordpress.org/plugins/woocommerce-poor-guys-swiss-knife/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-poor-guys-swiss-knife/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-poor-guys-swiss-knife/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-poor-guys-swiss-knife/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-poor-guys-swiss-knife/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-poor-guys-swiss-knife/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [ulihake](https://wordpress.org/support/users/ulih/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/select-options-from-xml-json-csv/#post-4686991)
 * Status: resolved