From 0070708cc6d2d7389648250653312ddb824fc408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=C3=ADna=20Vysko=C4=8Dilov=C3=A1?= Date: Tue, 14 Nov 2023 21:20:02 +0100 Subject: [PATCH] Add compaibility with autofill --- assets/js/public.js | 7 ++++++- assets/js/public.min.js | 2 +- includes/settings.php | 21 ++++++++++++++++++--- src/js/public.js | 6 ++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/assets/js/public.js b/assets/js/public.js index 2a5be96..6a07408 100644 --- a/assets/js/public.js +++ b/assets/js/public.js @@ -232,7 +232,12 @@ woolab_add_class_ok(ico_class); if (woolab.ares_fill) { - // Update values + // Compatibility with Fluid Checkout for WooCommerce – Lite + if ($('#billing_same_as_shipping') && $('#billing_same_as_shipping').is(':checked')) { + $('#billing_same_as_shipping').click(); + } // Update values + + $('#billing_company').val(data.spolecnost).attr('readonly', true); $('#billing_dic').val(data.dic).attr('readonly', true); $('#billing_address_1').val(data.adresa).attr('readonly', true); diff --git a/assets/js/public.min.js b/assets/js/public.min.js index 2c18e41..40c601e 100644 --- a/assets/js/public.min.js +++ b/assets/js/public.min.js @@ -1 +1 @@ -"use strict";!function(i){var l="";function e(){var e;switch(woolab.ares_fill&&(i(".woolab-ic-dic-tip").remove(),c()),i("#billing_ic_field").slideDown(),i("#billing_dic_field").slideDown(),i("#billing_country").val()){case"SK":i("#billing_dic_dph_field").slideDown(),i("#billing_dic_field > label").addClass("woolab-ic-dic-required");break;case"CZ":i("#billing_dic_dph_field").slideUp(),i("#billing_dic_field > label").removeClass("woolab-ic-dic-required");break;default:i("#billing_dic_dph_field").slideUp(),i("#billing_dic_field > label").removeClass("woolab-ic-dic-required")}woolab.ares_check&&(t(e=i("#billing_ic")),i(document.body).on("focusin","#billing_ic",function(){l=e.val()}),e.donetyping(function(){(e=i("#billing_ic")).val()!==l&&t(e)},500)),i("#billing_company_field").slideDown()}function o(){var l="SK"==i("#billing_country").val()?"billing_dic_dph":"billing_dic";i("#billing_company, #billing_ic, #billing_dic, #billing_dic_dph").each(function(e,o){o.getAttribute("data-value")&&(o.value=o.getAttribute("data-value"),o.id==l&&o.value.length&&i(document.body).trigger("update_checkout"))})}function n(i){i.removeClass("kbnt-wrong").removeClass("woocommerce-invalid")}function a(i){i.addClass("kbnt-wrong").addClass("woocommerce-invalid").removeClass("woocommerce-validated")}function c(){i("#billing_company").removeAttr("readonly"),i("#billing_dic").removeAttr("readonly"),i("#billing_postcode").removeAttr("readonly"),i("#billing_city").removeAttr("readonly"),i("#billing_address_1").removeAttr("readonly")}function t(e){if("CZ"===i("#billing_country").val()){var o=e.val();if(o!==l){var t=i("#billing_ic_field"),r=''+woolab.l18n_not_valid+"";i(".woolab-ic-dic-tip").remove(),n(t),t.removeClass("kbnt-ok").removeClass("woocommerce-validated"),7!=o.length&&8!=o.length||null==o.match(/^[0-9]+$/)?(c(),o.length>0?a(t):n(t)):i.ajax({url:woolab.ajaxurl,data:{action:"ajaxAres",ico:o},beforeSend:function(){t.addClass("kbnt-validating"),t.append(''+woolab.l18n_validating+"")},success:function(l){(t.removeClass("kbnt-validating"),l)?0==(l=JSON.parse(l)).error?(i(".woolab-ic-dic-tip").remove(),t.addClass("kbnt-ok").addClass("woocommerce-validated").removeClass("woocommerce-invalid"),woolab.ares_fill&&(i("#billing_company").val(l.spolecnost).attr("readonly",!0),i("#billing_dic").val(l.dic).attr("readonly",!0),i("#billing_address_1").val(l.adresa).attr("readonly",!0),i("#billing_postcode").val(l.psc).attr("readonly",!0),i("#billing_city").val(l.mesto).attr("readonly",!0),t.append(''+woolab.l18n_ok+""),i("body").trigger("update_checkout"))):(d(t),i(".woolab-ic-dic-tip").length>0&&i(".woolab-ic-dic-tip").remove(),c(),t.append(''+l.error+"")):(d(t),0==i(".woolab-ic-dic-tip").length&&(c(),t.append(r)))},error:function(l){0==i(".woolab-ic-dic-tip").length&&(e.val(""),d(t),t.append(''+woolab.l18n_error+""))}}),l=e.val()}}}function d(l){woolab.ares_fill&&(i("#billing_company").val(""),i("#billing_dic").val(""),i("#billing_postcode").val(""),i("#billing_city").val(""),i("#billing_address_1").val(""),c()),a(l)}i.fn.extend({donetyping:function(l,e){e=e||1e3;var o,n=function(i){o&&(o=null,l.call(i))};return this.each(function(l,a){var c=i(a);c.is(":input")&&i(document.body).on("keyup keypress paste",a,function(i){"keyup"==i.type&&8!=i.keyCode||(o&&clearTimeout(o),o=setTimeout(function(){n(a)},e))}),c.is(":input")&&i(document.body).on("blur",a,function(){n(a)})})}}),i(document).ready(function(){i(document.body).on("input",".woolab-ic-dic-no_spaces input",function(){i(this).val(function(i,l){return l.replace(/\s+/g,"")})});var l=i("#billing_iscomp");l.length&&!l.prop("checked")||(o(),e()),i(document.body).on("change","#billing_country, #billing_iscomp",function(){var l,n=i("#billing_iscomp");!n.length||n.prop("checked")?(o(),e()):(i(".woolab-ic-dic-toggle").slideUp(),l="SK"==i("#billing_country").val()?"billing_dic_dph":"billing_dic",i("#billing_company, #billing_ic, #billing_dic, #billing_dic_dph").each(function(e,o){o.setAttribute("data-value",o.value),o.id==l&&o.value.length&&i(document.body).trigger("update_checkout"),o.value=""}))}),i("#billing_dic, #billing_dic_dph").donetyping(function(){var l=i("#billing_country").val();"SK"!=l&&"billing_dic"==this.id&&i(document.body).trigger("update_checkout"),"SK"==l&&"billing_dic_dph"==this.id&&i(document.body).trigger("update_checkout")},750)})}(jQuery); \ No newline at end of file +"use strict";!function(i){var l="";function e(){var e;switch(woolab.ares_fill&&(i(".woolab-ic-dic-tip").remove(),c()),i("#billing_ic_field").slideDown(),i("#billing_dic_field").slideDown(),i("#billing_country").val()){case"SK":i("#billing_dic_dph_field").slideDown(),i("#billing_dic_field > label").addClass("woolab-ic-dic-required");break;case"CZ":i("#billing_dic_dph_field").slideUp(),i("#billing_dic_field > label").removeClass("woolab-ic-dic-required");break;default:i("#billing_dic_dph_field").slideUp(),i("#billing_dic_field > label").removeClass("woolab-ic-dic-required")}woolab.ares_check&&(t(e=i("#billing_ic")),i(document.body).on("focusin","#billing_ic",function(){l=e.val()}),e.donetyping(function(){(e=i("#billing_ic")).val()!==l&&t(e)},500)),i("#billing_company_field").slideDown()}function n(){var l="SK"==i("#billing_country").val()?"billing_dic_dph":"billing_dic";i("#billing_company, #billing_ic, #billing_dic, #billing_dic_dph").each(function(e,n){n.getAttribute("data-value")&&(n.value=n.getAttribute("data-value"),n.id==l&&n.value.length&&i(document.body).trigger("update_checkout"))})}function o(i){i.removeClass("kbnt-wrong").removeClass("woocommerce-invalid")}function a(i){i.addClass("kbnt-wrong").addClass("woocommerce-invalid").removeClass("woocommerce-validated")}function c(){i("#billing_company").removeAttr("readonly"),i("#billing_dic").removeAttr("readonly"),i("#billing_postcode").removeAttr("readonly"),i("#billing_city").removeAttr("readonly"),i("#billing_address_1").removeAttr("readonly")}function t(e){if("CZ"===i("#billing_country").val()){var n=e.val();if(n!==l){var t=i("#billing_ic_field"),r=''+woolab.l18n_not_valid+"";i(".woolab-ic-dic-tip").remove(),o(t),t.removeClass("kbnt-ok").removeClass("woocommerce-validated"),7!=n.length&&8!=n.length||null==n.match(/^[0-9]+$/)?(c(),n.length>0?a(t):o(t)):i.ajax({url:woolab.ajaxurl,data:{action:"ajaxAres",ico:n},beforeSend:function(){t.addClass("kbnt-validating"),t.append(''+woolab.l18n_validating+"")},success:function(l){(t.removeClass("kbnt-validating"),l)?0==(l=JSON.parse(l)).error?(i(".woolab-ic-dic-tip").remove(),t.addClass("kbnt-ok").addClass("woocommerce-validated").removeClass("woocommerce-invalid"),woolab.ares_fill&&(i("#billing_same_as_shipping")&&i("#billing_same_as_shipping").is(":checked")&&i("#billing_same_as_shipping").click(),i("#billing_company").val(l.spolecnost).attr("readonly",!0),i("#billing_dic").val(l.dic).attr("readonly",!0),i("#billing_address_1").val(l.adresa).attr("readonly",!0),i("#billing_postcode").val(l.psc).attr("readonly",!0),i("#billing_city").val(l.mesto).attr("readonly",!0),t.append(''+woolab.l18n_ok+""),i("body").trigger("update_checkout"))):(d(t),i(".woolab-ic-dic-tip").length>0&&i(".woolab-ic-dic-tip").remove(),c(),t.append(''+l.error+"")):(d(t),0==i(".woolab-ic-dic-tip").length&&(c(),t.append(r)))},error:function(l){0==i(".woolab-ic-dic-tip").length&&(e.val(""),d(t),t.append(''+woolab.l18n_error+""))}}),l=e.val()}}}function d(l){woolab.ares_fill&&(i("#billing_company").val(""),i("#billing_dic").val(""),i("#billing_postcode").val(""),i("#billing_city").val(""),i("#billing_address_1").val(""),c()),a(l)}i.fn.extend({donetyping:function(l,e){e=e||1e3;var n,o=function(i){n&&(n=null,l.call(i))};return this.each(function(l,a){var c=i(a);c.is(":input")&&i(document.body).on("keyup keypress paste",a,function(i){"keyup"==i.type&&8!=i.keyCode||(n&&clearTimeout(n),n=setTimeout(function(){o(a)},e))}),c.is(":input")&&i(document.body).on("blur",a,function(){o(a)})})}}),i(document).ready(function(){i(document.body).on("input",".woolab-ic-dic-no_spaces input",function(){i(this).val(function(i,l){return l.replace(/\s+/g,"")})});var l=i("#billing_iscomp");l.length&&!l.prop("checked")||(n(),e()),i(document.body).on("change","#billing_country, #billing_iscomp",function(){var l,o=i("#billing_iscomp");!o.length||o.prop("checked")?(n(),e()):(i(".woolab-ic-dic-toggle").slideUp(),l="SK"==i("#billing_country").val()?"billing_dic_dph":"billing_dic",i("#billing_company, #billing_ic, #billing_dic, #billing_dic_dph").each(function(e,n){n.setAttribute("data-value",n.value),n.id==l&&n.value.length&&i(document.body).trigger("update_checkout"),n.value=""}))}),i("#billing_dic, #billing_dic_dph").donetyping(function(){var l=i("#billing_country").val();"SK"!=l&&"billing_dic"==this.id&&i(document.body).trigger("update_checkout"),"SK"==l&&"billing_dic_dph"==this.id&&i(document.body).trigger("update_checkout")},750)})}(jQuery); \ No newline at end of file diff --git a/includes/settings.php b/includes/settings.php index b2ec161..208de3e 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -3,12 +3,16 @@ add_filter('woocommerce_general_settings', 'woolab_icdic_icdic_general_settings'); function woolab_icdic_icdic_general_settings($settings) { + $vies_check_disabled = false; + $vat_check_disabled = false; + if ( class_exists('SoapClient') ) { $vies_desc = __( 'Enable validation of VAT number in EU database VIES.', 'woolab-ic-dic' ); $vies_check = 'yes'; } else { $vies_desc = '' . __( 'To enable this feature, turn on Soap Client (ask your hosting).', 'woolab-ic-dic' ) . ' ' . __( 'Enable validation of VAT number in EU database VIES.', 'woolab-ic-dic' ) ; $vies_check = 'yes'; + $vies_check_disabled = true; } $vat_desc = __( 'Enable VAT exemption for valid EU VAT numbers', 'woolab-ic-dic' ); @@ -17,6 +21,7 @@ function woolab_icdic_icdic_general_settings($settings) { } else { $vat_desc = $vat_desc . '
' . __( 'To enable this feature, turn on taxes in your store.', 'woolab-ic-dic' ) . ''; $vat_check = 'no'; + $vat_check_disabled = true; $wc_countries = new WC_Countries(); $vat_countries = $wc_countries->get_european_union_countries('eu_vat'); @@ -27,6 +32,12 @@ function woolab_icdic_icdic_general_settings($settings) { } } + if (class_exists("FluidCheckout")) { + $fluid_checkout = true; + } else { + $fluid_checkout = false; + } + $settings[] = array( 'title' => __( 'Kybernaut IČO DIČ options', 'woolab-ic-dic' ), 'type' => 'title', 'desc' => __( 'The following options affect how Business ID and VAT number behaves.', 'woolab-ic-dic' ), 'id' => 'woolab_icdic_options' ); $settings[] = array( 'title' => __( 'CZ: Validate Business ID in ARES', 'woolab-ic-dic' ), @@ -48,6 +59,7 @@ function woolab_icdic_icdic_general_settings($settings) { 'id' => 'woolab_icdic_vies_check', 'default' => $vies_check, 'type' => 'checkbox', + 'disabled' => $vies_check_disabled, ); $settings[] = array( 'title' => __( 'EU: VAT exempt', 'woolab-ic-dic' ), @@ -55,20 +67,23 @@ function woolab_icdic_icdic_general_settings($settings) { 'id' => 'woolab_icdic_vat_exempt_switch', 'default' => $vat_check, 'type' => 'checkbox', + 'disabled' => $vat_check_disabled, ); $settings[] = array( 'title' => __( 'Toggle fields visibility', 'woolab-ic-dic' ), - 'desc' => __( 'Enable toggle switch to show/hide input fields', 'woolab-ic-dic' ), - 'id' => 'woolab_icdic_toggle_switch', + 'desc' => __( 'Enable toggle switch to show/hide input fields', 'woolab-ic-dic' ) . ( class_exists("FluidCheckout") ? '
' . __("This feature is not compatible with Fluid Checkout for WooCommerce.", 'woolab-ic-dic') . '': ""), + 'id' => 'woolab_icdic_toggle_swithch', 'default' => 'no', 'type' => 'checkbox', + 'disabled' => class_exists("FluidCheckout") ? true : false, ); $settings[] = array( 'title' => __( 'Move Country to top', 'woolab-ic-dic' ), - 'desc' => __( 'Move Country field above the "Buying as a company" toggle', 'woolab-ic-dic' ), + 'desc' => __( 'Move Country field above the "Buying as a company" toggle', 'woolab-ic-dic' ) . ( class_exists("FluidCheckout") ? '
' . __("This feature is not compatible with Fluid Checkout for WooCommerce.", 'woolab-ic-dic') . '': ""), 'id' => 'woolab_icdic_country_switch', 'default' => 'no', 'type' => 'checkbox', + 'disabled' => class_exists("FluidCheckout") ? true : false, ); $settings[] = array( 'type' => 'sectionend', 'id' => 'woolab_icdic_options' ); diff --git a/src/js/public.js b/src/js/public.js index 3af6941..e79a8f5 100644 --- a/src/js/public.js +++ b/src/js/public.js @@ -225,6 +225,12 @@ if ( woolab.ares_fill ) { + // Compatibility with Fluid Checkout for WooCommerce – Lite + if ($('#billing_same_as_shipping') && $('#billing_same_as_shipping').is(':checked')) { + $('#billing_same_as_shipping').click(); + $('#fc-expansible-form-section__toggle-plus--billing_company').click(); + } + // Update values $('#billing_company').val(data.spolecnost).attr('readonly', true); $('#billing_dic').val(data.dic).attr('readonly', true);