Skip to content

Commit

Permalink
fixed compatibility with checkout manager,fixed js remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Preciousomonze committed Aug 5, 2019
1 parent 923dcba commit a115fd5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ If you have suggestions or a new feature request, feel free to get in touch with
* First release 🤗 🥳
### 1.0.1 - July 15, 2019
* Fix: Proper sanitizing
### 1.1.0 - August 10, 2019
### 1.1.0 - August 04, 2019
* Fix: Made error message a little bit more descriptive
* Fix: Removed appended element when not needed
* Added: Enables validation on Billing Address Page
### 1.1.1 - August 06, 2019
* Fix: Js remove element
* Fix: Compatibility with checkout manager when the checkout fields are altered
* Fix: Validation loop hole

## Screenshots ##

Expand Down
11 changes: 8 additions & 3 deletions assets/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var $ = jQuery;
// here, the index maps to the error code returned from getValidationError
var wcPvPhoneErrorMap = [ "Invalid number", "Invalid country code", "Phone number too short", "Phone number too long", "Invalid number"];
//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');
}
var wcPvPhoneIntl = $('.wc-pv-intl input').intlTelInput({
initialCountry: $(`${wcPvJson.parentPage} #billing_country`).val(),
/*geoIpLookup: function(callback) {
Expand Down Expand Up @@ -37,7 +40,7 @@ function wcPvValidatePhone(input){
}
else{
let errorCode = phone.intlTelInput("getValidationError");
wcPvphoneErrMsg = `Phone validation error: ${wcPvPhoneErrorMap[errorCode]}`;
wcPvphoneErrMsg = `Phone validation error: ${(wcPvPhoneErrorMap[errorCode] == undefined ? 'Internal Error': wcPvPhoneErrorMap[errorCode])}`;
}
return result;
}
Expand All @@ -51,18 +54,20 @@ $(`${wcPvJson.parentPage} #billing_country`).change(function(){
*/
function wcPvValidateProcess(parentEl){
let phoneNumber = wcPvValidatePhone(wcPvPhoneIntl);
if($('.wc-pv-intl input').length == 0)//doesnt exist, no need
return;
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.remove('#wc-ls-phone-valid-field-err-msg');
$('#wc-ls-phone-valid-field-err-msg').remove();
}
else{
if($('#wc-ls-phone-valid-field-err-msg').length == 0){//append
parentEl.append(`<input id="wc-ls-phone-valid-field-err-msg" value="${wcPvphoneErrMsg}" type="hidden" name="${wcPvJson.phoneValidatorErrName}">`);
}
parentEl.remove('#wc-ls-phone-valid-field');
$('#wc-ls-phone-valid-field').remove();
}
}
//for woocommerce checkout
Expand Down
12 changes: 7 additions & 5 deletions assets/js/frontend.min.js

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

6 changes: 5 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
= 1.1.0 =
* Fix: Made error message a little bit more descriptive
* Fix: Removed appended element when not needed
* Added: Enables validation on Billing Address Page
* Added: Enables validation on Billing Address Page
= 1.1.1 =
* Fix: Js remove element
* Fix: Compatibility with checkout manager when the checkout fields are altered
* Fix: Validation loop hole
2 changes: 1 addition & 1 deletion public/class-woocommerce-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function checkout_validate($data){
$bil_email = sanitize_email($_POST['billing_email']);
$bil_phone = sanitize_text_field($_POST['billing_phone']);

if( !empty($bil_email) && !empty($bil_phone) && (empty($phone_valid_field) || !is_numeric($phone_valid_field) ) ){//there was an error, this way we know its coming directly from normal woocommerce, so no conflict :)
if( !empty($bil_email) && !empty($bil_phone) && (!empty($phone_valid_err_field)) && (empty($phone_valid_field) || !is_numeric($phone_valid_field) ) ){//there was an error, this way we know its coming directly from normal woocommerce, so no conflict :)
$ph = explode(':',$phone_valid_err_field);
$ph[0] = '<strong>'.$ph[0].'</strong>';
$phone_err_msg = implode(':',$ph);
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Yes you can, check out the [github repo here](https://github.com/Preciousomonze/
* Fix: Made error message a little bit more descriptive
* Fix: Removed appended element when not needed
* Added: Enables validation on Billing Address Page
= 1.1.1 =
* Fix: Js remove element
* Fix: Compatibility with checkout manager when the checkout fields are altered
* Fix: Validation loop hole

== Upgrade notice ==
None
Expand Down
4 changes: 2 additions & 2 deletions wc-pv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Phone Validator for WooCommerce Helps in validating international telephone numbers on woocommerce billing address.
* Author: Precious Omonze (Code Explorer)
* Author URI: https://codeexplorer.ninja
* Version: 1.1.0
* Version: 1.1.1
* Requires at least: 4.9
* Tested up to: 5.2
* WC requires at least: 3.0
Expand All @@ -21,7 +21,7 @@
define('WC_PV_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define('WC_PV_PLUGIN_FILE', __FILE__ );
define('WC_PV_TEXT_DOMAIN', 'woocommerce');
define('WC_PV_PLUGIN_VERSION','1.1.0');
define('WC_PV_PLUGIN_VERSION','1.1.1');

/**
* environment, should be either test or production
Expand Down
Binary file modified woocommerce-phone-validator.zip
Binary file not shown.

0 comments on commit a115fd5

Please sign in to comment.