forked from chitezh/woocommerce_states_places
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added six new countries: * Algeria (DZ): Departments (Wilaya) and Municipalities (Baladiyahs) (thanks to [Walid Yacine MAZED](https://github.com/w-mazed)) * Brazil (BR): States and Municipalities ([country request](chitezh#35) - issue chitezh#35) * Nicaragua (NI): Departments and Cities (thanks to [ahc505](https://github.com/ahc505)) * Russia (RU): States and Cities (thanks to [Sarge Madovsky](https://github.com/SargeMadovsky)) * Spain (ES): Provinces and Municipalities (thanks to [Javier Esteban](https://profiles.wordpress.org/nobnob/)) * Tunisia (TN): Governorates (thanks to [Anouar Ben Saad](https://github.com/anouarbensaad)) * Updated 2 countries: * Chile (CL): states codes (thanks to [Luis Urrutia](https://github.com/LuisUrrutia)) * Guatemala (GT): missing municipalities (thanks to [macnomo](https://github.com/macnomo)) * Added localization to "State" and "City" field labels * Tested up to WooCommerce 4.0.1 This commit close #3, close chitezh#27, close chitezh#35, close chitezh#37 and close chitezh#39
- Loading branch information
1 parent
48cd31a
commit e1268c8
Showing
30 changed files
with
23,381 additions
and
1,676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
=== States, Cities, and Places for Woocommerce === | ||
Contributors: chitezh, luisurrutiaf, yordansoares, nobnob | ||
Donate link: https://github.com/chitezh | ||
Tags: woocommerce, states, cities, local government, dropdown, city, city select, cities select, city dropdown, cities dropdown, woocommerce city, woocommerce cities, Nigeria, Chile | ||
Requires at least: 4.7.14 | ||
Tested up to: 5.4 | ||
Requires PHP: 7.0 | ||
Stable tag: 1.2.2 | ||
WC requires at least: 3.0.x | ||
WC tested up to: 4.0.1 | ||
License: GPLv2 or later | ||
License URI: [http://www.gnu.org/licenses/gpl-2.0.html](http://www.gnu.org/licenses/gpl-2.0.html) | ||
|
||
Wordpress plugin that shows dropdowns for State and City Select for woocomerce | ||
|
||
== Description == | ||
|
||
This WooCommerce plugin transforms the text input for states, the city or town. With this plugin you can provide a list of states and cities to be shown as a select dropdown. | ||
|
||
This will be shown in checkout pages, edit addresses pages, shipping calculator, etc. | ||
|
||
= Supported Countries = | ||
* Algeria | ||
* Brazil | ||
* Chile | ||
* Guatemala | ||
* Nicaragua | ||
* Nigeria | ||
* Panama | ||
* Russia | ||
* Spain | ||
* Tunisia | ||
* Venezuela | ||
|
||
== Installation == | ||
|
||
= Minimum Requirements = | ||
|
||
WordPress 4.0 or greater | ||
Woocommerce 2.2 or greater | ||
PHP version 5.2.4 or greater | ||
MySQL version 5.0 or greater | ||
|
||
= Automatic installation = | ||
|
||
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don’t need to leave your web browser. To do an automatic install of WooCommerce, log in to your WordPress dashboard, navigate to the Plugins menu and click `Add New`. | ||
|
||
Search for `States, Cities, and Places for Woocommerce`, install and activate | ||
|
||
= Manual installation = | ||
|
||
[See wordpress codex](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation) | ||
|
||
= Updating = | ||
|
||
Automatic updates should work like a charm; as is the best practice, back up should be undertaken before updates. | ||
|
||
If on the off-chance you do encounter issues with the shop/category pages after an update you simply need to flush the permalinks by going to WordPress > Settings > Permalinks and hitting 'save'. That should return things to normal. | ||
|
||
== Frequently Asked Questions == | ||
|
||
= How do I report bugs? = | ||
Kindly create an issue stating the bug and how you caught it [https://github.com/chitezh/woocommerce_states_places/issues/new](https://github.com/chitezh/woocommerce_states_places/issues/new). | ||
|
||
= Can I suggest a new place or location? = | ||
Yes, you can always suggest or request new locations by creating an issue in [chitezh/woocommerce_states_places](https://github.com/chitezh/woocommerce_states_places/issues/new). Please refer to the [Country Codes](https://github.com/woocommerce/woocommerce/blob/master/i18n/countries.php) using by WooCommerce. | ||
|
||
= How do I contribute to the project? = | ||
You extend the plugin to cover countries, states and places. we accept pull requests. Fork the repo and make changes to /trunk. Consider reading [wordpress faq](https://wordpress.org/plugins/about/faq/) to further understand wordpress svn file structure. | ||
|
||
Pull Requests | ||
|
||
Document any change in behaviour - Make sure the README.md and any other relevant documentation are kept up-to-date. | ||
|
||
Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option. | ||
|
||
Create feature branches - Don't ask us to pull from your master branch. | ||
|
||
One pull request per feature - If you want to do more than one thing, send multiple pull requests. | ||
|
||
Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. | ||
|
||
== Screenshots == | ||
1. States dropdown. | ||
2. States dropdown on search. | ||
3. Cities dropdown on search. | ||
4. Selected state and city. | ||
|
||
== Changelog == | ||
= 1.2.2 - March 22, 2020 = | ||
* Added six new countries: | ||
* Algeria (DZ): Departments (Wilaya) and Municipalities (Baladiyahs) (thanks to [Walid Yacine MAZED](https://github.com/w-mazed)) | ||
* Brazil (BR): States and Municipalities ([country request](https://github.com/chitezh/woocommerce_states_places/issues/35) - issue #35) | ||
* Nicaragua (NI): Departments and Cities (thanks to [ahc505](https://github.com/ahc505)) | ||
* Russia (RU): States and Cities (thanks to [Sarge Madovsky](https://github.com/SargeMadovsky)) | ||
* Spain (ES): Provinces and Municipalities (thanks to [Javier Esteban](https://profiles.wordpress.org/nobnob/)) | ||
* Tunisia (TN): Governorates (thanks to [Anouar Ben Saad](https://github.com/anouarbensaad)) | ||
* Updated 2 countries: | ||
* Chile (CL): states codes (thanks to [Luis Urrutia](https://github.com/LuisUrrutia)) | ||
* Guatemala (GT): missing municipalities (thanks to [macnomo](https://github.com/macnomo)) | ||
* Added localization to "State" and "City" field labels | ||
* Tested up to WooCommerce 4.0.1 | ||
= 1.2.1 - March 18, 2020 = | ||
* Added two new countries: | ||
* Panama (PA): Provinces, Districts and Corregimientos | ||
* Venezuela (VE): States and Municipalities (with their capitals) | ||
* Invert the order of State and City fields to have more sense with the steps of form. | ||
* Fix text domain in plugin header comment (states-cities-and-places-for-woocommerce). | ||
* Fix some typos and strings without translation functions. | ||
= 1.2.0 - February 07, 2019 = | ||
* Added a new country: Guatemala (GT) | ||
= 1.1.1 - August 28, 2018 = | ||
* Updated Chilean states and cities (16 states, no numbers). | ||
= 1.1.0 - July 09, 2017 = | ||
* Added a new country: Chile (CL) | ||
= 1.0.2 - August 11, 2016 = | ||
* Change author name. | ||
= 1.0.1 - August 10, 2016 = | ||
* Updated README file. | ||
= 1.0 - August 10, 2016 = | ||
* First release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( '<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" placeholder="' + placeholder + '" />' ); | ||
} | ||
|
||
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( '<select name="' + input_name + '" id="' + input_id + '" class="city_select" placeholder="' + placeholder + '"></select>' ); | ||
//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 + '<option value="' + cityName + '">' + cityName + '</option>'; | ||
} | ||
} | ||
|
||
$citybox.html( '<option value="">' + wc_city_select_params.i18n_select_city_text + '</option>' + options ); | ||
|
||
if ( $('option[value="'+value+'"]', $citybox).length ) { | ||
$citybox.val( value ).change(); | ||
} else { | ||
$citybox.val( '' ).change(); | ||
} | ||
|
||
$( document.body ).trigger( 'city_to_select' ); | ||
} | ||
}); |
Oops, something went wrong.