Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Preciousomonze committed Jul 31, 2020
1 parent 1735638 commit 27a7f60
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 183 deletions.
120 changes: 65 additions & 55 deletions .wordpress-org/assets/js/frontend.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
/* script */
var $ = jQuery;
//$(document).ready(function(){
//set phone number properly for intl
// here, the index maps to the error code returned from getValidationError
// $(document).ready(function(){
// set phone number properly for intl
// here, the index maps to the error code returned from getValidationError
var wcPvPhoneErrorMap = wcPvJson.validationErrors;
//start
if($('.wc-pv-intl input').length == 0){//add class, some checkout plugin has overriden my baby
$('#billing_phone_field').addClass('wc-pv-phone wc-pv-intl');
// start
if ($( '.wc-pv-intl input' ).length == 0) {// add class, some checkout plugin has overriden my baby
$( '#billing_phone_field' ).addClass( 'wc-pv-phone wc-pv-intl' );
}
// Set default country.
var wcPvDefCountry = ( wcPvJson.defaultCountry === '' ? $( `${wcPvJson.parentPage} #biling_country` ).val() : wcPvJson.defaultCountry );
var wcPvDefCountry = ( wcPvJson.defaultCountry == '' ? $( `${wcPvJson.parentPage} #billing_country` ).val() : wcPvJson.defaultCountry );

let separateDialCode = ( wcPvJson.separateDialCode == 1 ? true : false );
let onlyCountries = wcPvJson.onlyCountries.map( value => { return value.toUpperCase(); } );
let onlyCountries = wcPvJson.onlyCountries.map( value => { return value.toUpperCase(); } );
// let preferredCountries = wcPvJson.preferredCountries.map( value => { return value.toUpperCase(); } );

var wcPvPhoneIntl = $('.wc-pv-intl input').intlTelInput({
initialCountry: ( wcPvDefCountry == '' ? 'NG' : wcPvDefCountry ),
onlyCountries: onlyCountries,
separateDialCode: separateDialCode,
utilsScript: wcPvJson.utilsScript,
//autoHideDialCode: true,
//nationalMode: false,
/* geoIpLookup: function(callback) {
$.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
const countryCode = (resp && resp.country) ? resp.country : '';//asking for payment shaa,smh
callback(countryCode);
});
},//to pick user country */
});
var wcPvPhoneIntl = $( '.wc-pv-intl input' ).intlTelInput(
{
initialCountry: ( ( wcPvDefCountry == '' || wcPvDefCountry == undefined ) ? 'NG' : wcPvDefCountry ),
onlyCountries: onlyCountries,
separateDialCode: separateDialCode,
utilsScript: wcPvJson.utilsScript,
preferredCountries: wcPvJson.preferredCountries,
//autoHideDialCode: true,
//nationalMode: false,
/* geoIpLookup: function(callback) {
$.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
const countryCode = (resp && resp.country) ? resp.country : '';//asking for payment shaa,smh
callback(countryCode);
});
},//to pick user country */
}
);

/*if(wcPvJson.userPhone !== undefined ){
wcPvPhoneIntl.intlTelInput("setNumber").val(wcPvJson.userPhone);
/*if (wcPvJson.userPhone !== undefined ) {
wcPvPhoneIntl.intlTelInput("setNumber").val(wcPvJson.userPhone);
}*/

// Some Globals.
var wcPvphoneErrMsg = '';

/**
* Validates the phone number
*
*
* @param intlTelInput input
* @return string or bool
*/
function wcPvValidatePhone( input ) {
const phone = input;
let result = false;
if ( phone.intlTelInput('isValidNumber') == true ) {
let result = false;
if ( phone.intlTelInput( 'isValidNumber' ) == true ) {
result = phone.intlTelInput( 'getNumber' );
}
else{
let errorCode = phone.intlTelInput( 'getValidationError' );
} else {
let errorCode = phone.intlTelInput( 'getValidationError' );
wcPvphoneErrMsg = `${wcPvJson.phoneErrorTitle + (wcPvPhoneErrorMap[errorCode] == undefined ? wcPvJson.phoneUnknownErrorMsg : wcPvPhoneErrorMap[errorCode])}`;
}
return result;
}

// Incase of country change
$ ( `${wcPvJson.parentPage} #billing_country` ).change( function() {
let value = $( this ).val();
$( `${wcPvJson.parentPage} #billing_country` ).change(
function() {
let value = $( this ).val();

// Make sure you only set if its in the selected countries
if ( onlyCountries.includes( value ) ) {
wcPvPhoneIntl.intlTelInput( 'setCountry', value );
// Make sure you only set if its in the selected countries
if ( onlyCountries.includes( value ) ) {
wcPvPhoneIntl.intlTelInput( 'setCountry', value );
}
}
});
);

// Adjust design if true.
if ( separateDialCode === true ) {
Expand All @@ -72,41 +77,46 @@ if ( separateDialCode === true ) {

/**
* Js validation process
* @param {object} parentEl the parent element
*
* @param {object} parentEl the parent element
*/
function wcPvValidateProcess( parentEl ) {
let phoneNumber = wcPvValidatePhone( wcPvPhoneIntl );
if ( $( '.wc-pv-intl input' ).length == 0) // Doesnt exist, no need.
if ( $( '.wc-pv-intl input' ).length == 0) { // Doesnt exist, no need.
return;
}

// Remove errors first, so its not stagnant, special thanks to Sylvain :)
$('#wc-ls-phone-valid-field-err-msg').remove();
$( '#wc-ls-phone-valid-field-err-msg' ).remove();

if( phoneNumber != false ){ // Phone is valid.
if ( phoneNumber != false ) { // Phone is valid.
$( `${wcPvJson.parentPage} input#billing_phone` ).val( phoneNumber ); // Set the real value so it submits it along.

if ( $( '#wc-ls-phone-valid-field' ).length == 0 ) { // Append.
parentEl.append(`<input id="wc-ls-phone-valid-field" value="${phoneNumber}" type="hidden" name="${wcPvJson.phoneValidatorName}">`);
parentEl.append( ` < input id = "wc-ls-phone-valid-field" value = "${phoneNumber}" type = "hidden" name = "${wcPvJson.phoneValidatorName}" > ` );
}
}
else{
parentEl.append( `<input id="wc-ls-phone-valid-field-err-msg" value="${wcPvphoneErrMsg}" type="hidden" name="${wcPvJson.phoneValidatorErrName}">` );
} else {
parentEl.append( ` < input id = "wc-ls-phone-valid-field-err-msg" value = "${wcPvphoneErrMsg}" type = "hidden" name = "${wcPvJson.phoneValidatorErrName}" > ` );
$( '#wc-ls-phone-valid-field' ).remove();
}
}

// For woocommerce checkout.
if( wcPvJson.currentPage == 'checkout' ) {
if ( wcPvJson.currentPage == 'checkout' ) {
let wcPvCheckoutForm = $( `${wcPvJson.parentPage}` );
wcPvCheckoutForm.on( 'checkout_place_order', function(){
wcPvValidateProcess( wcPvCheckoutForm );
});
}
else if( wcPvJson.currentPage == 'account') { // For account page.
let wcPvAccForm = $(`${wcPvJson.parentPage} form`);
$( `${wcPvJson.parentPage}` ).submit( function(){
wcPvValidateProcess( wcPvAccForm );
});
wcPvCheckoutForm.on(
'checkout_place_order',
function(){
wcPvValidateProcess( wcPvCheckoutForm );
}
);
} else if ( wcPvJson.currentPage == 'account') { // For account page.
let wcPvAccForm = $( `${wcPvJson.parentPage} form` );
$( `${wcPvJson.parentPage}` ).submit(
function(){
wcPvValidateProcess( wcPvAccForm );
}
);
}

//});
// });
2 changes: 1 addition & 1 deletion .wordpress-org/assets/js/frontend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .wordpress-org/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@

= 1.2.1 =
* Update: Adjusted stable tag, Github Actions wahala and struggle, some svn structure clean up.

= 1.3.0 =
* Fix: typo for billing_phone in js file.
* New: Enable Preferred Countries listing using filter.
11 changes: 11 additions & 0 deletions .wordpress-org/includes/class-wc-pv.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ public function get_default_country() {
*/
public function get_allowed_countries() {
return apply_filters( 'wc_pv_allowed_countries', array_keys( WC()->countries->get_allowed_countries() ) );
}

/**
* Gets Preferred countries
*
* @since 1.3.0
*
* @return array
*/
public function get_preferred_countries() {
return apply_filters( 'wc_pv_preferred_countries', array() );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions .wordpress-org/languages/woo-phone-validator.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# This file is distributed under the same license as the Phone Validator for WooCommerce package.
msgid ""
msgstr ""
"Project-Id-Version: Phone Validator for WooCommerce 1.2.1\n"
"Project-Id-Version: Phone Validator for WooCommerce 1.3.0\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/woocommerce-phone-validator\n"
"POT-Creation-Date: 2020-07-28 20:26:51+00:00\n"
"POT-Creation-Date: 2020-07-31 20:38:08+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion .wordpress-org/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "woo-phone-validator",
"textDomain": "woo-phone-validator",
"mainFile": "wc-pv.php",
"version": "1.2.0",
"version": "1.3.0",
"description": "Forces validation of WooCommerce phone field on checkout and billing address edit page ",
"license": "GPL-3.0",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions .wordpress-org/public/class-woocommerce-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function enqueue_js(){
'validationErrors' => wc_pv()->get_validation_errors(),
'defaultCountry' => wc_pv()->get_default_country(),
'onlyCountries' => wc_pv()->get_allowed_countries(),
'preferredCountries' => wc_pv()->get_preferred_countries(),
'utilsScript' => wc_pv()->plugin_url() . '/assets/vendor/js/utils.js',
);
//get phone value for international lib use
Expand Down
35 changes: 8 additions & 27 deletions .wordpress-org/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Contributors: preciousomonze,helgatheviking
Tags: woocommerce,phone number validator,checkout phone validator,account phone validator,woocommerce validation
Requires at least: 4.9
Tested up to: 5.4
Requires PHP: 7.0
Requires PHP: 5.6
License: GNU General Public License v3.0
License URI: https://github.com/Preciousomonze/woocommerce-phone-validator/blob/master/LICENSE
Donate link: https://rave.flutterwave.com/pay/preciousomonze
Stable tag: 1.2.1
Stable tag: 1.3.0

Phone Validator for WooCommerce Helps in validating international telephone numbers on WooCommerce billing address.

Expand Down Expand Up @@ -39,35 +39,16 @@ If you have suggestions or a new feature request, feel free to get in touch with
== Frequently Asked Questions ==

= What do I need, to use the plugin? =

1. You need to have WooCommerce plugin installed and activated on your WordPress site.

= Do you have a sample of using your filter hooks to customize the plugin? 👀🥶 =
Sure fam! I like to ease things for people. 💆🏽‍♂️ check out the list of hooks and sample usage, [click here](https://gist.github.com/Preciousomonze/03c54e7e0cc0e11ca709832bc757810b).

= I noticed some issues, how can i report it? =
Oops, sorry about that, you can submit an issue [by clicking here](https://github.com/Preciousomonze/woocommerce-phone-validator/issues)
Awwwwn 😊, sorry about that, you can submit an issue [by clicking here](https://github.com/Preciousomonze/woocommerce-phone-validator/issues).

= Can I contribute to the codes of this plugin? =
Yes you can, check out the [github repo here](https://github.com/Preciousomonze/woocommerce-phone-validator/)

== Changelog ==

= 1.0.0 =
* lauhcing first version.
= 1.0.1 =
* Fix: Proper sanitizing
= 1.1.0 =
* Added: Enables validation on Billing Address Page
= 1.1.1 =
* Fix: Compatibility with checkout manager when the checkout fields are altered
= 1.2.0 =
* New: Translation support for error messages, ikr! finally 😂 (I am sincerely sorry).
* New: Enable country code after flag(Operation Separate Dial Code) using filter 'wc_pv_separate_dial_code', set to true ☺️
* New: Ability to set default country using filter 'wc_pv_set_default_country'
* New: Phone field now uses same list of allowed countries in your WooCommerce settings by default ( Thanks to Helgatheviking 🤾🏻‍♀️)
* New: Enable altering list of allowed countries using filter hooks
* Update: Tested up to WordPress 5.4 🥳🥳
* Update: Tested up to WooCommerce 4.3 🥳🥳
= 1.2.1 =
* Update: Adjusted stable tag, Github Actions wahala and struggle, some svn structure clean up.
Yes you can, check out the [github repo here](https://github.com/Preciousomonze/woocommerce-phone-validator/).

== Upgrade notice ==
Translation support. IKR! finally 😂 (I am sincerely sorry).
Expand All @@ -79,4 +60,4 @@ New filter hooks to help customize some things, view Changelog for more info.

2. Error shown to user when an invalid phone number is submitted on checkout

3. Error show to user when an invalid phone number is submitted on the billing address edit page
3. Error shown to user when an invalid phone number is submitted on the billing address edit page
4 changes: 2 additions & 2 deletions .wordpress-org/wc-pv.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Description: Phone Validator for WooCommerce Helps in validating international telephone numbers on WooCommerc billing address.
* Author: Precious Omonzejele (CodeXplorer 🤾🏽‍♂️🥞🦜🤡)
* Author URI: https://codexplorer.ninja
* Version: 1.2.1
* Version: 1.3.0
* Requires at least: 5.0
* Tested up to: 5.4
* WC requires at least: 3.0
Expand All @@ -30,7 +30,7 @@
define( 'WC_PV_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'WC_PV_PLUGIN_FILE', __FILE__ );
define( 'WC_PV_TEXT_DOMAIN', 'woo-phone-validator' );
define( 'WC_PV_PLUGIN_VERSION', '1.2.1' );
define( 'WC_PV_PLUGIN_VERSION', '1.3.0' );

/**
* Environment, should be either test or production
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
**Contributors:** __Helgatheviking 🤾🏻‍♀️__


**Donate link:** <a href="https://rave.flutterwave.com/pay/preciousomonze" target="_blank">__Drop something for your boy 🤓 🥳__</a>
**Donate link:** I do not mind a token for ordering Pancakes 🥞, so you can <a href="https://rave.flutterwave.com/pay/preciousomonze" target="_blank">__Drop something for your boy 🤓 🥳__</a>

**Tags:** woocommerce, preciousomonze plugin, phone validator, intlTelInput, woocommerce phone validator

**Requires at least:** 4.9
**Requires at least:** 5.0

**Tested up to:** 5.4

**Stable tag:** 1.2.1
**Requires PHP:** 5.6

**Stable tag:** 1.3.0

**License:** GPLv3 or later

Expand Down Expand Up @@ -51,14 +53,16 @@ If you have suggestions or a new feature request, feel free to get in touch with
## Frequently Asked Questions

### What do I need to use the plugin?

1. You need to have WooCommerce plugin installed and activated on your WordPress site.

### Do you have a sample of using your filter hooks to customize the plugin? 👀🥶
Sure fam! I like to ease things for people. 💆🏽‍♂️ check out the list of hooks and sample usage, [click here](https://gist.github.com/Preciousomonze/03c54e7e0cc0e11ca709832bc757810b).

### I noticed some issues, how can i report it?
Oops, sorry about that, you can submit an issue [by clicking here](https://github.com/Preciousomonze/woocommerce-phone-validator/issues)
Awwwwn 😊, sorry about that, you can submit an issue [by clicking here](https://github.com/Preciousomonze/woocommerce-phone-validator/issues).

### Can I contribute to the codes of this plugin?
Yes you can, check out the [github repo here](https://github.com/Preciousomonze/woocommerce-phone-validator/)
Yes you can, check out the [github repo here](https://github.com/Preciousomonze/woocommerce-phone-validator/).

## Changelog

Expand Down Expand Up @@ -96,6 +100,6 @@ Yes you can, check out the [github repo here](https://github.com/Preciousomonze/
###
![Screenshot 2](https://github.com/Preciousomonze/woocommerce-phone-validator/blob/master/assets/images/screenshot-2.PNG)

### 3. Error show to user when an invalid phone number is submitted on the billing address edit page
### 3. Error shown to user when an invalid phone number is submitted on the billing address edit page
###
![Screenshot 3](https://github.com/Preciousomonze/woocommerce-phone-validator/blob/master/assets/images/screenshot-3.png)
Loading

0 comments on commit 27a7f60

Please sign in to comment.