diff --git a/lib/wc-city-select/assets/js/city-select.js b/lib/wc-city-select/assets/js/city-select.js new file mode 100644 index 0000000..6028a6e --- /dev/null +++ b/lib/wc-city-select/assets/js/city-select.js @@ -0,0 +1,180 @@ +jQuery( function($) { + + // wc_city_select_params is required to continue, ensure the object exists + // wc_country_select_params is used for select2 texts. This one is added by WC + if ( typeof wc_country_select_params === 'undefined' || typeof wc_city_select_params === 'undefined' ) { + return false; + } + + function getEnhancedSelectFormatString() { + var formatString = { + formatMatches: function( matches ) { + if ( 1 === matches ) { + return wc_country_select_params.i18n_matches_1; + } + + return wc_country_select_params.i18n_matches_n.replace( '%qty%', matches ); + }, + formatNoMatches: function() { + return wc_country_select_params.i18n_no_matches; + }, + formatAjaxError: function() { + return wc_country_select_params.i18n_ajax_error; + }, + formatInputTooShort: function( input, min ) { + var number = min - input.length; + + if ( 1 === number ) { + return wc_country_select_params.i18n_input_too_short_1; + } + + return wc_country_select_params.i18n_input_too_short_n.replace( '%qty%', number ); + }, + formatInputTooLong: function( input, max ) { + var number = input.length - max; + + if ( 1 === number ) { + return wc_country_select_params.i18n_input_too_long_1; + } + + return wc_country_select_params.i18n_input_too_long_n.replace( '%qty%', number ); + }, + formatSelectionTooBig: function( limit ) { + if ( 1 === limit ) { + return wc_country_select_params.i18n_selection_too_long_1; + } + + return wc_country_select_params.i18n_selection_too_long_n.replace( '%qty%', limit ); + }, + formatLoadMore: function() { + return wc_country_select_params.i18n_load_more; + }, + formatSearching: function() { + return wc_country_select_params.i18n_searching; + } + }; + + return formatString; + } + + // Select2 Enhancement if it exists + if ( $().select2 ) { + var wc_city_select_select2 = function() { + $( 'select.city_select:visible' ).each( function() { + var select2_args = $.extend({ + placeholderOption: 'first', + width: '100%' + }, getEnhancedSelectFormatString() ); + + $( this ).select2( select2_args ); + }); + }; + + wc_city_select_select2(); + + $( document.body ).bind( 'city_to_select', function() { + wc_city_select_select2(); + }); + } + + /* City select boxes */ + var cities_json = wc_city_select_params.cities.replace( /"/g, '"' ); + var cities = $.parseJSON( cities_json ); + + $( 'body' ).on( 'country_to_state_changing', function(e, country, $container) { + var $statebox = $container.find( '#billing_state, #shipping_state, #calc_shipping_state' ); + var state = $statebox.val(); + $( document.body ).trigger( 'state_changing', [country, state, $container ] ); + }); + + $( 'body' ).on( 'change', 'select.state_select, #calc_shipping_state', function() { + var $container = $( this ).closest( 'div' ); + var country = $container.find( '#billing_country, #shipping_country, #calc_shipping_country' ).val(); + var state = $( this ).val(); + + $( document.body ).trigger( 'state_changing', [country, state, $container ] ); + }); + + $( 'body' ).on( 'state_changing', function(e, country, state, $container) { + var $citybox = $container.find( '#billing_city, #shipping_city, #calc_shipping_city' ); + + if ( cities[ country ] ) { + /* if the country has no states */ + if( cities[country] instanceof Array) { + cityToSelect( $citybox, cities[ country ] ); + } else if ( state ) { + if ( cities[ country ][ state ] ) { + cityToSelect( $citybox, cities[ country ][ state ] ); + } else { + cityToInput( $citybox ); + } + } else { + disableCity( $citybox ); + } + } else { + cityToInput( $citybox ); + } + }); + + /* Ajax replaces .cart_totals (child of .cart-collaterals) on shipping calculator */ + if ( $( '.cart-collaterals' ).length && $( '#calc_shipping_state' ).length ) { + var calc_observer = new MutationObserver( function() { + $( '#calc_shipping_state' ).change(); + }); + calc_observer.observe( document.querySelector( '.cart-collaterals' ), { childList: true }); + } + + function cityToInput( $citybox ) { + if ( $citybox.is('input') ) { + $citybox.prop( 'disabled', false ); + return; + } + + var input_name = $citybox.attr( 'name' ); + var input_id = $citybox.attr( 'id' ); + var placeholder = $citybox.attr( 'placeholder' ); + + $citybox.parent().find( '.select2-container' ).remove(); + + $citybox.replaceWith( '' ); + } + + function disableCity( $citybox ) { + $citybox.val( '' ).change(); + $citybox.prop( 'disabled', true ); + } + + function cityToSelect( $citybox, current_cities ) { + var value = $citybox.val(); + + if ( $citybox.is('input') ) { + var input_name = $citybox.attr( 'name' ); + var input_id = $citybox.attr( 'id' ); + var placeholder = $citybox.attr( 'placeholder' ); + + $citybox.replaceWith( '' ); + //we have to assign the new object, because of replaceWith + $citybox = $('#'+input_id); + } else { + $citybox.prop( 'disabled', false ); + } + + var options = ''; + for( var index in current_cities ) { + if ( current_cities.hasOwnProperty( index ) ) { + var cityName = current_cities[ index ]; + options = options + ''; + } + } + + $citybox.html( '' + options ); + + if ( $('option[value="'+value+'"]', $citybox).length ) { + $citybox.val( value ).change(); + } else { + $citybox.val( '' ).change(); + } + + $( document.body ).trigger( 'city_to_select' ); + } +}); diff --git a/lib/wc-city-select/cities/CO.php b/lib/wc-city-select/cities/CO.php new file mode 100644 index 0000000..0053f6e --- /dev/null +++ b/lib/wc-city-select/cities/CO.php @@ -0,0 +1,1170 @@ + array( + 'Leticia', + 'Puerto Nariño' + ), + 'ANT' => array( + 'Abejorral', + 'Abriaquí', + 'Alejandria', + 'Amagá', + 'Amalfi', + 'Andes', + 'Angelópolis', + 'Angostura', + 'Anorí', + 'Anzá', + 'Apartadó', + 'Arboletes', + 'Argelia', + 'Armenia', + 'Barbosa', + 'Bello', + 'Belmira', + 'Betania', + 'Betulia', + 'Bolívar', + 'Briceño', + 'Burítica', + 'Cáceres', + 'Caicedo', + 'Caldas', + 'Campamento', + 'Cañasgordas', + 'Caracolí', + 'Caramanta', + 'Carepa', + 'Carmen de Viboral', + 'Carolina', + 'Caucasia', + 'Chigorodó', + 'Cisneros', + 'Cocorná', + 'Concepción', + 'Concordia', + 'Copacabana', + 'Dabeiba', + 'Don Matías', + 'Ebéjico', + 'El Bagre', + 'Entrerríos', + 'Envigado', + 'Fredonia', + 'Frontino', + 'Giraldo', + 'Girardota', + 'Gómez Plata', + 'Granada', + 'Guadalupe', + 'Guarne', + 'Guatapé', + 'Heliconia', + 'Hispania', + 'Itagüí', + 'Ituango', + 'Jardín', + 'Jericó', + 'La Ceja', + 'La Estrella', + 'La Pintada', + 'La Unión', + 'Liborina', + 'Maceo', + 'Marinilla', + 'Medellín', + 'Montebello', + 'Murindó', + 'Mutatá', + 'Nariño', + 'Nechí', + 'Necoclí', + 'Olaya', + 'Peñol', + 'Peque', + 'Pueblorrico', + 'Puerto Berrío', + 'Puerto Nare', + 'Puerto Triunfo', + 'Remedios', + 'Retiro', + 'Ríonegro', + 'Sabanalarga', + 'Sabaneta', + 'Salgar', + 'San Andrés de Cuerquía', + 'San Carlos', + 'San Francisco', + 'San Jerónimo', + 'San José de Montaña', + 'San Juan de Urabá', + 'San Luís', + 'San Pedro', + 'San Pedro de Urabá', + 'San Rafael', + 'San Roque', + 'San Vicente', + 'Santa Bárbara', + 'Santa Fé de Antioquia', + 'Santa Rosa de Osos', + 'Santo Domingo', + 'Santuario', + 'Segovia', + 'Sonsón', + 'Sopetrán', + 'Támesis', + 'Tarazá', + 'Tarso', + 'Titiribí', + 'Toledo', + 'Turbo', + 'Uramita', + 'Urrao', + 'Valdivia', + 'Valparaiso', + 'Vegachí', + 'Venecia', + 'Vigía del Fuerte', + 'Yalí', + 'Yarumal', + 'Yolombó', + 'Yondó (Casabe)', + 'Zaragoza' + ), + 'ARA' => array( + 'Arauca', + 'Arauquita', + 'Cravo Norte', + 'Fortúl', + 'Puerto Rondón', + 'Saravena', + 'Tame' + ), + 'ATL' => array( + 'Baranoa', + 'Barranquilla', + 'Campo de la Cruz', + 'Candelaria', + 'Galapa', + 'Juan de Acosta', + 'Luruaco', + 'Malambo', + 'Manatí', + 'Palmar de Varela', + 'Piojo', + 'Polonuevo', + 'Ponedera', + 'Puerto Colombia', + 'Repelón', + 'Sabanagrande', + 'Sabanalarga', + 'Santa Lucía', + 'Santo Tomás', + 'Soledad', + 'Suan', + 'Tubará', + 'Usiacuri' + ), + 'BOL' => array( + 'Achí', + 'Altos del Rosario', + 'Arenal', + 'Arjona', + 'Arroyohondo', + 'Barranco de Loba', + 'Calamar', + 'Cantagallo', + 'Cartagena', + 'Cicuco', + 'Clemencia', + 'Córdoba', + 'El Carmen de Bolívar', + 'El Guamo', + 'El Peñon', + 'Hatillo de Loba', + 'Magangué', + 'Mahates', + 'Margarita', + 'María la Baja', + 'Mompós', + 'Montecristo', + 'Morales', + 'Norosí', + 'Pinillos', + 'Regidor', + 'Río Viejo', + 'San Cristobal', + 'San Estanislao', + 'San Fernando', + 'San Jacinto', + 'San Jacinto del Cauca', + 'San Juan de Nepomuceno', + 'San Martín de Loba', + 'San Pablo', + 'Santa Catalina', + 'Santa Rosa', + 'Santa Rosa del Sur', + 'Simití', + 'Soplaviento', + 'Talaigua Nuevo', + 'Tiquisio (Puerto Rico)', + 'Turbaco', + 'Turbaná', + 'Villanueva', + 'Zambrano' + ), + 'BOY' => array( + 'Almeida', + 'Aquitania', + 'Arcabuco', + 'Belén', + 'Berbeo', + 'Beteitiva', + 'Boavita', + 'Boyacá', + 'Briceño', + 'Buenavista', + 'Busbanza', + 'Caldas', + 'Campohermoso', + 'Cerinza', + 'Chinavita', + 'Chiquinquirá', + 'Chíquiza', + 'Chiscas', + 'Chita', + 'Chitaraque', + 'Chivatá', + 'Chívor', + 'Ciénaga', + 'Cómbita', + 'Coper', + 'Corrales', + 'Covarachía', + 'Cubará', + 'Cucaita', + 'Cuitiva', + 'Duitama', + 'El Cocuy', + 'El Espino', + 'Firavitoba', + 'Floresta', + 'Gachantivá', + 'Gámeza', + 'Garagoa', + 'Guacamayas', + 'Guateque', + 'Guayatá', + 'Guicán', + 'Izá', + 'Jenesano', + 'Jericó', + 'La Capilla', + 'La Uvita', + 'La Victoria', + 'Labranzagrande', + 'Macanal', + 'Maripí', + 'Miraflores', + 'Mongua', + 'Monguí', + 'Moniquirá', + 'Motavita', + 'Muzo', + 'Nobsa', + 'Nuevo Colón', + 'Oicatá', + 'Otanche', + 'Pachavita', + 'Páez', + 'Paipa', + 'Pajarito', + 'Panqueba', + 'Pauna', + 'Paya', + 'Paz de Río', + 'Pesca', + 'Pisva', + 'Puerto Boyacá', + 'Quipama', + 'Ramiriquí', + 'Ráquira', + 'Rondón', + 'Saboyá', + 'Sáchica', + 'Samacá', + 'San Eduardo', + 'San José de Pare', + 'San Luís de Gaceno', + 'San Mateo', + 'San Miguel de Sema', + 'San Pablo de Borbur', + 'Santa María', + 'Santa Rosa de Viterbo', + 'Santa Sofía', + 'Santana', + 'Sativanorte', + 'Sativasur', + 'Siachoque', + 'Soatá', + 'Socha', + 'Socotá', + 'Sogamoso', + 'Somondoco', + 'Sora', + 'Soracá', + 'Sotaquirá', + 'Susacón', + 'Sutamarchán', + 'Sutatenza', + 'Tasco', + 'Tenza', + 'Tibaná', + 'Tibasosa', + 'Tinjacá', + 'Tipacoque', + 'Toca', + 'Toguí', + 'Topagá', + 'Tota', + 'Tunja', + 'Tunungua', + 'Turmequé', + 'Tuta', + 'Tutasá', + 'Úmbita', + 'Ventaquemada', + 'Villa de Leiva', + 'Viracachá', + 'Zetaquirá' + ), + 'CAL' => array( + 'Aguadas', + 'Anserma', + 'Aranzazu', + 'Belalcázar', + 'Chinchiná', + 'Filadelfia', + 'La Dorada', + 'La Merced', + 'La Victoria', + 'Manizales', + 'Manzanares', + 'Marmato', + 'Marquetalia', + 'Marulanda', + 'Neira', + 'Norcasia', + 'Pácora', + 'Palestina', + 'Pensilvania', + 'Río Sucio', + 'Risaralda', + 'Salamina', + 'Samaná', + 'San José', + 'Supía', + 'Villamaría', + 'Viterbo' + ), + 'CAQ' => array( + 'Albania', + 'Belén de los Andaquíes', + 'Cartagena del Chairá', + 'Curillo', + 'El Doncello', + 'El Paujil', + 'Florencia', + 'La Montañita', + 'Milán', + 'Morelia', + 'Puerto Rico', + 'San José del Fragua', + 'San Vicente del Caguán', + 'Solano', + 'Solita', + 'Valparaiso' + ), + 'CAS' => array( + 'Aguazul', + 'Chámeza', + 'Hato Corozal', + 'La Salina', + 'Maní', + 'Monterrey', + 'Nunchía', + 'Orocué', + 'Paz de Ariporo', + 'Pore', + 'Recetor', + 'Sabanalarga', + 'Sácama', + 'San Luís de Palenque', + 'Támara', + 'Tauramena', + 'Trinidad', + 'Villanueva', + 'Yopal' + ), + 'CAU' => array( + 'Almaguer', + 'Argelia', + 'Balboa', + 'Bolívar', + 'Buenos Aires', + 'Cajibío', + 'Caldono', + 'Caloto', + 'Corinto', + 'El Tambo', + 'Florencia', + 'Guachené', + 'Guapí', + 'Inzá', + 'Jambaló', + 'La Sierra', + 'La Vega', + 'López (Micay)', + 'Mercaderes', + 'Miranda', + 'Morales', + 'Padilla', + 'Páez (Belalcazar)', + 'Patía (El Bordo)', + 'Piamonte', + 'Piendamó', + 'Popayán', + 'Puerto Tejada', + 'Puracé (Coconuco)', + 'Rosas', + 'San Sebastián', + 'Santa Rosa', + 'Santander de Quilichao', + 'Silvia', + 'Sotara (Paispamba)', + 'Suárez', + 'Sucre', + 'Timbío', + 'Timbiquí', + 'Toribío', + 'Totoró', + 'Villa Rica' + ), + 'CES' => array( + 'Aguachica', + 'Agustín Codazzi', + 'Astrea', + 'Becerríl', + 'Bosconia', + 'Chimichagua', + 'Chiriguaná', + 'Curumaní', + 'El Copey', + 'El Paso', + 'Gamarra', + 'Gonzalez', + 'La Gloria', + 'La Jagua de Ibirico', + 'La Paz (Robles)', + 'Manaure Balcón del Cesar', + 'Pailitas', + 'Pelaya', + 'Pueblo Bello', + 'Río de oro', + 'San Alberto', + 'San Diego', + 'San Martín', + 'Tamalameque', + 'Valledupar' + ), + 'CHO' => array( + 'Acandí', + 'Alto Baudó (Pie de Pato)', + 'Atrato (Yuto)', + 'Bagadó', + 'Bahía Solano (Mútis)', + 'Bajo Baudó (Pizarro)', + 'Belén de Bajirá', + 'Bojayá (Bellavista)', + 'Cantón de San Pablo', + 'Carmen del Darién (CURBARADÓ)', + 'Cértegui', + 'Condoto', + 'El Carmen de Atrato', + 'Istmina', + 'Juradó', + 'Lloró', + 'Medio Atrato', + 'Medio Baudó', + 'Medio San Juan (ANDAGOYA)', + 'Novita', + 'Nuquí', + 'Quibdó', + 'Río Iró', + 'Río Quito', + 'Ríosucio', + 'San José del Palmar', + 'Santa Genoveva de Docorodó', + 'Sipí', + 'Tadó', + 'Unguía', + 'Unión Panamericana (ÁNIMAS)' + ), + 'COR' => array( + 'Ayapel', + 'Buenavista', + 'Canalete', + 'Cereté', + 'Chimá', + 'Chinú', + 'Ciénaga de Oro', + 'Cotorra', + 'La Apartada y La Frontera', + 'Lorica', + 'Los Córdobas', + 'Momil', + 'Moñitos', + 'Montelíbano', + 'Monteria', + 'Planeta Rica', + 'Pueblo Nuevo', + 'Puerto Escondido', + 'Puerto Libertador', + 'Purísima', + 'Sahagún', + 'San Andrés Sotavento', + 'San Antero', + 'San Bernardo del Viento', + 'San Carlos', + 'San José de Uré', + 'San Pelayo', + 'Tierralta', + 'Tuchín', + 'Valencia' + ), + 'CUN' => array( + 'Agua de Dios', + 'Albán', + 'Anapoima', + 'Anolaima', + 'Apulo', + 'Arbeláez', + 'Beltrán', + 'Bituima', + 'Bogotá D.C.', + 'Bojacá', + 'Cabrera', + 'Cachipay', + 'Cajicá', + 'Caparrapí', + 'Cáqueza', + 'Carmen de Carupa', + 'Chaguaní', + 'Chía', + 'Chipaque', + 'Choachí', + 'Chocontá', + 'Cogua', + 'Cota', + 'Cucunubá', + 'El Colegio', + 'El Peñón', + 'El Rosal', + 'Facatativá', + 'Fómeque', + 'Fosca', + 'Funza', + 'Fúquene', + 'Fusagasugá', + 'Gachalá', + 'Gachancipá', + 'Gachetá', + 'Gama', + 'Girardot', + 'Granada', + 'Guachetá', + 'Guaduas', + 'Guasca', + 'Guataquí', + 'Guatavita', + 'Guayabal de Siquima', + 'Guayabetal', + 'Gutiérrez', + 'Jerusalén', + 'Junín', + 'La Calera', + 'La Mesa', + 'La Palma', + 'La Peña', + 'La Vega', + 'Lenguazaque', + 'Machetá', + 'Madrid', + 'Manta', + 'Medina', + 'Mosquera', + 'Nariño', + 'Nemocón', + 'Nilo', + 'Nimaima', + 'Nocaima', + 'Pacho', + 'Paime', + 'Pandi', + 'Paratebueno', + 'Pasca', + 'Puerto Salgar', + 'Pulí', + 'Quebradanegra', + 'Quetame', + 'Quipile', + 'Ricaurte', + 'San Antonio de Tequendama', + 'San Bernardo', + 'San Cayetano', + 'San Francisco', + 'San Juan de Río Seco', + 'Sasaima', + 'Sesquilé', + 'Sibaté', + 'Silvania', + 'Simijaca', + 'Soacha', + 'Sopó', + 'Subachoque', + 'Suesca', + 'Supatá', + 'Susa', + 'Sutatausa', + 'Tabio', + 'Tausa', + 'Tena', + 'Tenjo', + 'Tibacuy', + 'Tibirita', + 'Tocaima', + 'Tocancipá', + 'Topaipí', + 'Ubalá', + 'Ubaque', + 'Ubaté', + 'Une', + 'Útica', + 'Venecia (Ospina Pérez)', + 'Vergara', + 'Viani', + 'Villagómez', + 'Villapinzón', + 'Villeta', + 'Viotá', + 'Yacopí', + 'Zipacón', + 'Zipaquirá' + ), + 'GUA' => array( 'Inírida' ), + 'GUV' => array( + 'Calamar', + 'El Retorno', + 'Miraflores', + 'San José del Guaviare' + ), + 'HUI' => array( + 'Acevedo', + 'Agrado', + 'Aipe', + 'Algeciras', + 'Altamira', + 'Baraya', + 'Campoalegre', + 'Colombia', + 'Elías', + 'Garzón', + 'Gigante', + 'Guadalupe', + 'Hobo', + 'Íquira', + 'Isnos', + 'La Argentina', + 'La Plata', + 'Nátaga', + 'Neiva', + 'Oporapa', + 'Paicol', + 'Palermo', + 'Palestina', + 'Pital', + 'Pitalito', + 'Rivera', + 'Saladoblanco', + 'San Agustín', + 'Santa María', + 'Suaza', + 'Tarqui', + 'Tello', + 'Teruel', + 'Tesalia', + 'Timaná', + 'Villavieja', + 'Yaguará' + ), + 'LAG' => array( + 'Albania', + 'Barrancas', + 'Dibulla', + 'Distracción', + 'El Molino', + 'Fonseca', + 'Hatonuevo', + 'La Jagua del Pilar', + 'Maicao', + 'Manaure', + 'Riohacha', + 'San Juan del Cesar', + 'Uribia', + 'Urumita', + 'Villanueva' + ), + 'MAG' => array( + 'Algarrobo', + 'Aracataca', + 'Ariguaní (El Difícil)', + 'Cerro San Antonio', + 'Chivolo', + 'Ciénaga', + 'Concordia', + 'El Banco', + 'El Piñon', + 'El Retén', + 'Fundación', + 'Guamal', + 'Nueva Granada', + 'Pedraza', + 'Pijiño', + 'Pivijay', + 'Plato', + 'Puebloviejo', + 'Remolino', + 'Sabanas de San Angel (SAN ANGEL)', + 'Salamina', + 'San Sebastián de Buenavista', + 'San Zenón', + 'Santa Ana', + 'Santa Bárbara de Pinto', + 'Santa Marta', + 'Sitionuevo', + 'Tenerife', + 'Zapayán (PUNTA DE PIEDRAS)', + 'Zona Bananera (PRADO - SEVILLA)' + ), + 'MET' => array( + 'Acacías', + 'Barranca de Upía', + 'Cabuyaro', + 'Castilla la Nueva', + 'Cubarral', + 'Cumaral', + 'El Calvario', + 'El Castillo', + 'El Dorado', + 'Fuente de Oro', + 'Granada', + 'Guamal', + 'La Macarena', + 'Lejanías', + 'Mapiripan', + 'Mesetas', + 'Puerto Concordia', + 'Puerto Gaitán', + 'Puerto Lleras', + 'Puerto López', + 'Puerto Rico', + 'Restrepo', + 'San Carlos de Guaroa', + 'San Juan de Arama', + 'San Juanito', + 'San Martín', + 'Uribe', + 'Villavicencio', + 'Vista Hermosa' + ), + 'NAR' => array( + 'Albán (San José)', + 'Aldana', + 'Ancuya', + 'Arboleda (Berruecos)', + 'Barbacoas', + 'Belén', + 'Buesaco', + 'Chachaguí', + 'Colón (Génova)', + 'Consaca', + 'Contadero', + 'Córdoba', + 'Cuaspud (Carlosama)', + 'Cumbal', + 'Cumbitara', + 'El Charco', + 'El Peñol', + 'El Rosario', + 'El Tablón de Gómez', + 'El Tambo', + 'Francisco Pizarro', + 'Funes', + 'Guachavés', + 'Guachucal', + 'Guaitarilla', + 'Gualmatán', + 'Iles', + 'Imúes', + 'Ipiales', + 'La Cruz', + 'La Florida', + 'La Llanada', + 'La Tola', + 'La Unión', + 'Leiva', + 'Linares', + 'Magüi (Payán)', + 'Mallama (Piedrancha)', + 'Mosquera', + 'Nariño', + 'Olaya Herrera', + 'Ospina', + 'Policarpa', + 'Potosí', + 'Providencia', + 'Puerres', + 'Pupiales', + 'Ricaurte', + 'Roberto Payán (San José)', + 'Samaniego', + 'San Bernardo', + 'San Juan de Pasto', + 'San Lorenzo', + 'San Pablo', + 'San Pedro de Cartago', + 'Sandoná', + 'Santa Bárbara (Iscuandé)', + 'Sapuyes', + 'Sotomayor (Los Andes)', + 'Taminango', + 'Tangua', + 'Tumaco', + 'Túquerres', + 'Yacuanquer' + ), + 'NSA' => array( + 'Ábrego', + 'Arboledas', + 'Bochalema', + 'Bucarasica', + 'Cáchira', + 'Cácota', + 'Chinácota', + 'Chitagá', + 'Convención', + 'Cúcuta', + 'Cucutilla', + 'Durania', + 'El Carmen', + 'El Tarra', + 'El Zulia', + 'Gramalote', + 'Hacarí', + 'Herrán', + 'La Esperanza', + 'La Playa', + 'Labateca', + 'Los Patios', + 'Lourdes', + 'Mutiscua', + 'Ocaña', + 'Pamplona', + 'Pamplonita', + 'Puerto Santander', + 'Ragonvalia', + 'Salazar', + 'San Calixto', + 'San Cayetano', + 'Santiago', + 'Sardinata', + 'Silos', + 'Teorama', + 'Tibú', + 'Toledo', + 'Villa Caro', + 'Villa del Rosario' + ), + 'PUT' => array( + 'Colón', + 'Mocoa', + 'Orito', + 'Puerto Asís', + 'Puerto Caicedo', + 'Puerto Guzmán', + 'Puerto Leguízamo', + 'San Francisco', + 'San Miguel', + 'Santiago', + 'Sibundoy', + 'Valle del Guamuez', + 'Villagarzón' + ), + 'QUI' => array( + 'Armenia', + 'Buenavista', + 'Calarcá', + 'Circasia', + 'Cordobá', + 'Filandia', + 'Génova', + 'La Tebaida', + 'Montenegro', + 'Pijao', + 'Quimbaya', + 'Salento' + ), + 'RIS' => array( + 'Apía', + 'Balboa', + 'Belén de Umbría', + 'Dos Quebradas', + 'Guática', + 'La Celia', + 'La Virginia', + 'Marsella', + 'Mistrató', + 'Pereira', + 'Pueblo Rico', + 'Quinchía', + 'Santa Rosa de Cabal', + 'Santuario' + ), + 'SAP' => array( 'Providencia' ), + 'SAN' => array( + 'Aguada', + 'Albania', + 'Aratoca', + 'Barbosa', + 'Barichara', + 'Barrancabermeja', + 'Betulia', + 'Bolívar', + 'Bucaramanga', + 'Cabrera', + 'California', + 'Capitanejo', + 'Carcasí', + 'Cepita', + 'Cerrito', + 'Charalá', + 'Charta', + 'Chima', + 'Chipatá', + 'Cimitarra', + 'Concepción', + 'Confines', + 'Contratación', + 'Coromoro', + 'Curití', + 'El Carmen', + 'El Guacamayo', + 'El Peñon', + 'El Playón', + 'Encino', + 'Enciso', + 'Florián', + 'Floridablanca', + 'Galán', + 'Gámbita', + 'Girón', + 'Guaca', + 'Guadalupe', + 'Guapota', + 'Guavatá', + 'Guepsa', + 'Hato', + 'Jesús María', + 'Jordán', + 'La Belleza', + 'La Paz', + 'Landázuri', + 'Lebrija', + 'Los Santos', + 'Macaravita', + 'Málaga', + 'Matanza', + 'Mogotes', + 'Molagavita', + 'Ocamonte', + 'Oiba', + 'Onzaga', + 'Palmar', + 'Palmas del Socorro', + 'Páramo', + 'Pie de Cuesta', + 'Pinchote', + 'Puente Nacional', + 'Puerto Parra', + 'Puerto Wilches', + 'Rio Negro', + 'Sabana de Torres', + 'San Andrés', + 'San Benito', + 'San Gíl', + 'San Joaquín', + 'San José de Miranda', + 'San Miguel', + 'San Vicente del Chucurí', + 'Santa Bárbara', + 'Santa Helena del Opón', + 'Simacota', + 'Socorro', + 'Suaita', + 'Sucre', + 'Suratá', + 'Tona', + 'Valle de San José', + 'Vélez', + 'Vetas', + 'Villanueva', + 'Zapatoca' + ), + 'SUC' => array( + 'Buenavista', + 'Caimito', + 'Chalán', + 'Colosó (Ricaurte)', + 'Corozal', + 'Coveñas', + 'El Roble', + 'Galeras (Nueva Granada)', + 'Guaranda', + 'La Unión', + 'Los Palmitos', + 'Majagual', + 'Morroa', + 'Ovejas', + 'Palmito', + 'Sampués', + 'San Benito Abad', + 'San Juan de Betulia', + 'San Marcos', + 'San Onofre', + 'San Pedro', + 'Sincé', + 'Sincelejo', + 'Sucre', + 'Tolú', + 'Tolú Viejo' + ), + 'TOL' => array( + 'Alpujarra', + 'Alvarado', + 'Ambalema', + 'Anzoátegui', + 'Armero (Guayabal)', + 'Ataco', + 'Cajamarca', + 'Carmen de Apicalá', + 'Casabianca', + 'Chaparral', + 'Coello', + 'Coyaima', + 'Cunday', + 'Dolores', + 'Espinal', + 'Falan', + 'Flandes', + 'Fresno', + 'Guamo', + 'Herveo', + 'Honda', + 'Ibagué', + 'Icononzo', + 'Lérida', + 'Líbano', + 'Mariquita', + 'Melgar', + 'Murillo', + 'Natagaima', + 'Ortega', + 'Palocabildo', + 'Piedras', + 'Planadas', + 'Prado', + 'Purificación', + 'Rioblanco', + 'Roncesvalles', + 'Rovira', + 'Saldaña', + 'San Antonio', + 'San Luis', + 'Santa Isabel', + 'Suárez', + 'Valle de San Juan', + 'Venadillo', + 'Villahermosa', + 'Villarrica' + ), + 'VAC' => array( + 'Alcalá', + 'Andalucía', + 'Ansermanuevo', + 'Argelia', + 'Bolívar', + 'Buenaventura', + 'Buga', + 'Bugalagrande', + 'Caicedonia', + 'Cali', + 'Calima (Darién)', + 'Candelaria', + 'Cartago', + 'Dagua', + 'El Águila', + 'El Cairo', + 'El Cerrito', + 'El Dovio', + 'Florida', + 'Ginebra', + 'Guacarí', + 'Jamundí', + 'La Cumbre', + 'La Unión', + 'La Victoria', + 'Obando', + 'Palmira', + 'Pradera', + 'Restrepo', + 'Riofrío', + 'Roldanillo', + 'San Pedro', + 'Sevilla', + 'Toro', + 'Trujillo', + 'Tulúa', + 'Ulloa', + 'Versalles', + 'Vijes', + 'Yotoco', + 'Yumbo', + 'Zarzal' + ), + 'VAU' => array( + 'Carurú', + 'Mitú', + 'Taraira' + ), + 'VID' => array( + 'Cumaribo', + 'La Primavera', + 'Puerto Carreño', + 'Santa Rosalía' + ), +); diff --git a/lib/wc-city-select/readme.txt b/lib/wc-city-select/readme.txt new file mode 100644 index 0000000..71644ce --- /dev/null +++ b/lib/wc-city-select/readme.txt @@ -0,0 +1,79 @@ +=== WC City Select === +Contributors: mantish +Donate link: mailto:paypal@8manos.com +Tags: woocommerce, cities, city, city select, cities select, city dropdown, cities dropdown, woocommerce city, woocommerce cities +Requires at least: 4.0 +Tested up to: 4.7.3 +Stable tag: 1.0.3 +WC requires at least: 2.2 +WC tested up to: 2.7.0 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +City Select for WooCommerce. Show a dropdown select as the cities input. + +== Description == + +WooCommerce uses a text input for the customers to enter the city or town. With this plugin you can provide a list of cities to be shown as a select dropdown. + +This will be shown in checkout pages, edit addresses pages and shipping calculator if it's configured that way. + +A list of cities has to be loaded in the functions.php file (the plugin already includes cities from Colombia and Iran). Please check the Installation section for more info. + +### Github + +Contribute at https://github.com/8manos/wc-city-select + +== Installation == + +1. Upload to the `/wp-content/plugins/` directory +1. Activate the plugin through the 'Plugins' menu in WordPress +1. Use `wc_city_select_cities` filter to load your cities. This is done similarly to [adding states/provinces](https://docs.woothemes.com/document/addmodify-states/). It should be added on your functions.php or a custom plugin. + +` +add_filter( 'wc_city_select_cities', 'my_cities' ); +/** + * Replace XX with the country code. Instead of YYY, ZZZ use actual state codes. + */ +function my_cities( $cities ) { + $cities['XX'] = array( + 'YYY' => array( + 'City ', + 'Another City' + ), + 'ZZZ' => array( + 'City 3', + 'City 4' + ) + ); + return $cities; +} +` + +It's also possible to use a list of cities without grouping them by state: + +` +add_filter( 'wc_city_select_cities', 'my_cities' ); +function my_cities( $cities ) { + $cities['XX'] = array( + 'City ', + 'Another City' + ); + return $cities; +} +` + +== Changelog == + += 1.0.3 = +* fix some issues when loading cities initially, that were causing warnings. + += 1.0.2 = +* fix some issues with shipping calculator and other edge cases. +* Now works with countries that have no states, only cities. + += 1.0.1 = +* select2 enhancement when available. Adds a JS version of the select dropdown. + += 1.0 = +* First release. diff --git a/lib/wc-city-select/wc-city-select.php b/lib/wc-city-select/wc-city-select.php new file mode 100644 index 0000000..a14a620 --- /dev/null +++ b/lib/wc-city-select/wc-city-select.php @@ -0,0 +1,196 @@ +cities ) ) { + $this->load_country_cities(); + } + + if ( ! is_null( $cc ) ) { + return isset( $this->cities[ $cc ] ) ? $this->cities[ $cc ] : false; + } else { + return $this->cities; + } + } + + public function load_country_cities() { + global $cities; + + // Load only the city files the shop owner wants/needs. + $allowed = array_merge( WC()->countries->get_allowed_countries(), WC()->countries->get_shipping_countries() ); + + if ( $allowed ) { + foreach ( $allowed as $code => $country ) { + if ( ! isset( $cities[ $code ] ) && file_exists( $this->get_plugin_path() . '/cities/' . $code . '.php' ) ) { + include( $this->get_plugin_path() . '/cities/' . $code . '.php' ); + } + } + } + + $this->cities = apply_filters( 'wc_city_select_cities', $cities ); + } + + public function form_field_city( $field, $key, $args, $value ) { + + // Do we need a clear div? + if ( ( ! empty( $args['clear'] ) ) ) { + $after = '
'; + } else { + $after = ''; + } + + // Required markup + if ( $args['required'] ) { + $args['class'][] = 'validate-required'; + $required = ' *'; + } else { + $required = ''; + } + + // Custom attribute handling + $custom_attributes = array(); + + if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { + foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) { + $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; + } + } + + // Validate classes + if ( ! empty( $args['validate'] ) ) { + foreach( $args['validate'] as $validate ) { + $args['class'][] = 'validate-' . $validate; + } + } + + // field p and label + $field = ''; + if ( $args['label'] ) { + $field .= ''; + } + + // Get Country + $country_key = $key == 'billing_city' ? 'billing_country' : 'shipping_country'; + $current_cc = WC()->checkout->get_value( $country_key ); + + $state_key = $key == 'billing_city' ? 'billing_state' : 'shipping_state'; + $current_sc = WC()->checkout->get_value( $state_key ); + + // Get country cities + $cities = $this->get_cities( $current_cc ); + + if ( is_array( $cities ) ) { + + $field .= ''; + + } else { + + $field .= ''; + } + + // field description and close wrapper + if ( $args['description'] ) { + $field .= '' . esc_attr( $args['description'] ) . ''; + } + + $field .= '
' . $after; + + return $field; + } + + public function load_scripts() { + if ( is_cart() || is_checkout() || is_wc_endpoint_url( 'edit-address' ) ) { + + $city_select_path = $this->get_plugin_url() . 'assets/js/city-select.js'; + wp_enqueue_script( 'wc-city-select', $city_select_path, array( 'jquery', 'woocommerce' ), self::VERSION, true ); + + $cities = json_encode( $this->get_cities() ); + wp_localize_script( 'wc-city-select', 'wc_city_select_params', array( + 'cities' => $cities, + 'i18n_select_city_text' => esc_attr__( 'Select an option…', 'woocommerce' ) + ) ); + } + } + + public function get_plugin_path() { + + if ( $this->plugin_path ) { + return $this->plugin_path; + } + + return $this->plugin_path = plugin_dir_path( __FILE__ ); + } + + public function get_plugin_url() { + + if ( $this->plugin_url ) { + return $this->plugin_url; + } + + return $this->plugin_url = plugin_dir_url( __FILE__ ); + } + } + + $GLOBALS['wc_city_select'] = new WC_City_Select(); +}