From 2afc658fd50c5f550fdc21eb91669555344b38df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=C3=ADna=20Vysko=C4=8Dilov=C3=A1?= Date: Tue, 9 Jan 2024 15:44:48 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Better=20compatibility=20Fluid=20Checkout?= =?UTF-8?q?=20for=20WooCommerce=20=E2=80=93=20Lite=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/public.js | 37 ++++++++++++++++++++++++++++++++++++- assets/js/public.min.js | 2 +- src/js/public.js | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/assets/js/public.js b/assets/js/public.js index 6a07408..5a3d24f 100644 --- a/assets/js/public.js +++ b/assets/js/public.js @@ -234,7 +234,42 @@ 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(); + // Check whether the CollapsibleBlock library is available + if (window.CollapsibleBlock) { + // Set billing address as different from shipping address + var fc_billing_same_as_shipping_field = document.querySelector('#billing_same_as_shipping'); + fc_billing_same_as_shipping_field.checked = false; // Expand the billing address fields + + var fc_billing_address_fields_wrapper = document.querySelector('#woocommerce-billing-fields__field-wrapper'); + + if (fc_billing_address_fields_wrapper) { + CollapsibleBlock.expand(fc_billing_address_fields_wrapper); + } // Get company field toggle and content elements + + + var fc_billing_company_toggle = document.querySelector('#fc-expansible-form-section__toggle-plus--billing_company'); + var fc_billing_company_content = document.querySelector('#fc-expansible-form-section__content--billing_company'); // Expand the billing company field + + if (fc_billing_company_toggle) { + CollapsibleBlock.collapse(fc_billing_company_toggle); + } + + if (fc_billing_company_content) { + CollapsibleBlock.expand(fc_billing_company_content); + } // Get dic field toggle and content elements + + + var fc_billing_dic_toggle = document.querySelector('#fc-expansible-form-section__toggle-plus--billing_dic'); + var fc_billing_dic_content = document.querySelector('#fc-expansible-form-section__content--billing_dic'); // Expand the billing dic field + + if (fc_billing_dic_toggle) { + CollapsibleBlock.collapse(fc_billing_dic_toggle); + } + + if (fc_billing_dic_content) { + CollapsibleBlock.expand(fc_billing_dic_content); + } + } } // Update values diff --git a/assets/js/public.min.js b/assets/js/public.min.js index 40c601e..9f060f3 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 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 +"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){if(t.removeClass("kbnt-validating"),l)if(0==(l=JSON.parse(l)).error){if(i(".woolab-ic-dic-tip").remove(),t.addClass("kbnt-ok").addClass("woocommerce-validated").removeClass("woocommerce-invalid"),woolab.ares_fill){if(i("#billing_same_as_shipping")&&i("#billing_same_as_shipping").is(":checked")&&window.CollapsibleBlock){document.querySelector("#billing_same_as_shipping").checked=!1;var e=document.querySelector("#woocommerce-billing-fields__field-wrapper");e&&CollapsibleBlock.expand(e);var o=document.querySelector("#fc-expansible-form-section__toggle-plus--billing_company"),n=document.querySelector("#fc-expansible-form-section__content--billing_company");o&&CollapsibleBlock.collapse(o),n&&CollapsibleBlock.expand(n);var a=document.querySelector("#fc-expansible-form-section__toggle-plus--billing_dic"),s=document.querySelector("#fc-expansible-form-section__content--billing_dic");a&&CollapsibleBlock.collapse(a),s&&CollapsibleBlock.expand(s)}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")}}else d(t),i(".woolab-ic-dic-tip").length>0&&i(".woolab-ic-dic-tip").remove(),c(),t.append(''+l.error+"");else 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 diff --git a/src/js/public.js b/src/js/public.js index e79a8f5..71bcc04 100644 --- a/src/js/public.js +++ b/src/js/public.js @@ -226,9 +226,40 @@ if ( woolab.ares_fill ) { // Compatibility with Fluid Checkout for WooCommerce – Lite + // https://wordpress.org/support/topic/compatibility-with-kybernaut-ico-dic-plugin/ 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(); + + // Check whether the CollapsibleBlock library is available + if ( window.CollapsibleBlock ) { + + // Set billing address as different from shipping address + var fc_billing_same_as_shipping_field = document.querySelector( '#billing_same_as_shipping' ); + fc_billing_same_as_shipping_field.checked = false; + + // Expand the billing address fields + var fc_billing_address_fields_wrapper = document.querySelector( '#woocommerce-billing-fields__field-wrapper' ); + if ( fc_billing_address_fields_wrapper ) { + CollapsibleBlock.expand( fc_billing_address_fields_wrapper ); + } + + // Get company field toggle and content elements + var fc_billing_company_toggle = document.querySelector( '#fc-expansible-form-section__toggle-plus--billing_company' ); + var fc_billing_company_content = document.querySelector( '#fc-expansible-form-section__content--billing_company' ); + + // Expand the billing company field + if ( fc_billing_company_toggle ) { CollapsibleBlock.collapse( fc_billing_company_toggle ); } + if ( fc_billing_company_content ) { CollapsibleBlock.expand( fc_billing_company_content ); } + + // Get dic field toggle and content elements + var fc_billing_dic_toggle = document.querySelector( '#fc-expansible-form-section__toggle-plus--billing_dic' ); + var fc_billing_dic_content = document.querySelector( '#fc-expansible-form-section__content--billing_dic' ); + + // Expand the billing dic field + if ( fc_billing_dic_toggle ) { CollapsibleBlock.collapse( fc_billing_dic_toggle ); } + if ( fc_billing_dic_content ) { CollapsibleBlock.expand( fc_billing_dic_content ); } + + } + } // Update values From 257d27d9e12abb6bc6bd94161eb98d7eea8c9d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=C3=ADna=20Vysko=C4=8Dilov=C3=A1?= Date: Tue, 9 Jan 2024 15:46:45 +0100 Subject: [PATCH 2/4] release alfa --- woolab-ic-dic.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/woolab-ic-dic.php b/woolab-ic-dic.php index fb39b49..392e75c 100644 --- a/woolab-ic-dic.php +++ b/woolab-ic-dic.php @@ -3,7 +3,7 @@ Plugin Name: Kybernaut IC DIC Plugin URI: https://kybernaut.cz/pluginy/kybernaut-ic-dic Description: Adds Czech Company & VAT numbers (IČO & DIČ) to WooCommerce billing fields and verifies if data are correct. - Version: 1.8.1 + Version: 1.8.2-alfa Author: Karolína Vyskočilová Author URI: https://kybernaut.cz Text Domain: woolab-ic-dic @@ -33,7 +33,7 @@ define( 'WOOLAB_IC_DIC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'WOOLAB_IC_DIC_ABSPATH', dirname( __FILE__ ) . '/' ); define( 'WOOLAB_IC_DIC_URL', plugin_dir_url( __FILE__ ) ); -define( 'WOOLAB_IC_DIC_VERSION', '1.8.1' ); +define( 'WOOLAB_IC_DIC_VERSION', '1.8.2-alfa' ); // Check if WooCommerce active function woolab_icdic_init() { From 05474693ab55870868d60554e9b30659a08ffa5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=C3=ADna=20Vysko=C4=8Dilov=C3=A1?= Date: Thu, 11 Jan 2024 18:56:58 +0100 Subject: [PATCH 3/4] fluid checkout show fields --- includes/compatibility/fluidcheckout.php | 13 +++++++++++++ woolab-ic-dic.php | 1 + 2 files changed, 14 insertions(+) create mode 100644 includes/compatibility/fluidcheckout.php diff --git a/includes/compatibility/fluidcheckout.php b/includes/compatibility/fluidcheckout.php new file mode 100644 index 0000000..ee920da --- /dev/null +++ b/includes/compatibility/fluidcheckout.php @@ -0,0 +1,13 @@ + Date: Mon, 15 Jan 2024 15:28:59 +0100 Subject: [PATCH 4/4] comment out fluid checkout showing fields --- includes/compatibility/fluidcheckout.php | 12 ++++++------ woolab-ic-dic.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/compatibility/fluidcheckout.php b/includes/compatibility/fluidcheckout.php index ee920da..cdeee4d 100644 --- a/includes/compatibility/fluidcheckout.php +++ b/includes/compatibility/fluidcheckout.php @@ -5,9 +5,9 @@ * * @see https://wordpress.org/support/topic/compatibility-with-kybernaut-ico-dic-plugin/#post-17330291 */ -// function woolab_icdic_fluidcheckout_add_optional_fields_skip_list( $skip_list ) { -// $skip_list[] = 'billing_ic'; -// $skip_list[] = 'billing_dic'; -// return $skip_list; -// } -// add_filter( 'fc_hide_optional_fields_skip_list', 'woolab_icdic_fluidcheckout_add_optional_fields_skip_list', 10 ); +function woolab_icdic_fluidcheckout_add_optional_fields_skip_list( $skip_list ) { + $skip_list[] = 'billing_ic'; + $skip_list[] = 'billing_dic'; + return $skip_list; +} +add_filter( 'fc_hide_optional_fields_skip_list', 'woolab_icdic_fluidcheckout_add_optional_fields_skip_list', 10 ); diff --git a/woolab-ic-dic.php b/woolab-ic-dic.php index a7d1d15..8e90581 100644 --- a/woolab-ic-dic.php +++ b/woolab-ic-dic.php @@ -81,7 +81,7 @@ function woolab_icdic_plugin_admin_notice() { include_once( WOOLAB_IC_DIC_ABSPATH . 'includes/settings.php'); // Compatibility include_once( WOOLAB_IC_DIC_ABSPATH . 'includes/compatibility/superfaktura.php'); - include_once( WOOLAB_IC_DIC_ABSPATH . 'includes/compatibility/fluidcheckout.php'); + // include_once( WOOLAB_IC_DIC_ABSPATH . 'includes/compatibility/fluidcheckout.php'); don't apply globally. add_filter( 'woocommerce_billing_fields' , 'woolab_icdic_billing_fields', 10, 2 ); add_filter( 'woocommerce_checkout_fields', 'woolab_icdic_checkout_fields', 10, 2);