Last active
October 29, 2025 12:00
-
-
Save xlplugins/4afac4eb85c4a56be02c9bcd78930762 to your computer and use it in GitHub Desktop.
Funnelkit Checkout: Disabled Next Button when packeta_shipping_method Value empty
This file contains hidden or 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
| class WFACP_Custom_Shipping_Method_Compatibility { | |
| public function __construct() { | |
| add_action( 'wfacp_internal_css', [ $this, 'add_js' ] ); | |
| } | |
| public function add_js() { | |
| ?> | |
| <script> | |
| (function($) { | |
| 'use strict'; | |
| var glsShippingMethods = [ | |
| 'gls_shipping_method_parcel_locker', | |
| 'gls_shipping_method_parcel_shop', | |
| 'gls_shipping_method_parcel_locker_zones', | |
| 'gls_shipping_method_parcel_shop_zones' | |
| ]; | |
| function checkShippingMethod() { | |
| if ($('.single_step').length === 0) { | |
| return; | |
| } | |
| var selectedMethod = $('input[name="shipping_method[0]"]:checked').val(); | |
| var nextButton = $('.single_step .wfacp_next_page_button'); | |
| if (nextButton.length === 0) { | |
| return; | |
| } | |
| // Check Packetery method | |
| if (selectedMethod === 'packetery_shipping_method:packetery_carrier_skzpoint') { | |
| var packetaInfo = $('.packeta-widget-info').html(); | |
| var isPickupPointSelected = packetaInfo && packetaInfo.trim() !== ''; | |
| if (isPickupPointSelected) { | |
| nextButton.removeClass('wfacp_button_disabled'); | |
| nextButton.prop('disabled', false); | |
| } else { | |
| nextButton.addClass('wfacp_button_disabled'); | |
| nextButton.prop('disabled', true); | |
| } | |
| } | |
| // Check GLS methods | |
| else if (glsShippingMethods.indexOf(selectedMethod) !== -1) { | |
| var glsPickupData = $('#gls-pickup-info-data').val(); | |
| if (glsPickupData && glsPickupData.trim() !== '') { | |
| nextButton.removeClass('wfacp_button_disabled'); | |
| nextButton.prop('disabled', false); | |
| } else { | |
| nextButton.addClass('wfacp_button_disabled'); | |
| nextButton.prop('disabled', true); | |
| } | |
| } | |
| // Enable button for other methods | |
| else { | |
| nextButton.removeClass('wfacp_button_disabled'); | |
| nextButton.prop('disabled', false); | |
| } | |
| } | |
| function bindShippingEvents() { | |
| if ($('.single_step').length === 0) { | |
| return; | |
| } | |
| $(document).on('change', '.single_step input[name="shipping_method[0]"]', function() { | |
| checkShippingMethod(); | |
| }); | |
| $(document.body).on('updated_checkout', function() { | |
| checkShippingMethod(); | |
| }); | |
| // Watch for Packetery widget changes | |
| var packetaInfoObserver = new MutationObserver(function() { | |
| checkShippingMethod(); | |
| }); | |
| var packetaInfoElement = $('.packeta-widget-info')[0]; | |
| if (packetaInfoElement) { | |
| packetaInfoObserver.observe(packetaInfoElement, { | |
| childList: true, | |
| characterData: true, | |
| subtree: true | |
| }); | |
| } | |
| // Watch for GLS pickup data changes | |
| var glsDataObserver = new MutationObserver(function() { | |
| checkShippingMethod(); | |
| }); | |
| var glsDataElement = $('#gls-pickup-info-data')[0]; | |
| if (glsDataElement) { | |
| glsDataObserver.observe(glsDataElement, { | |
| attributes: true, | |
| attributeFilter: ['value'] | |
| }); | |
| } | |
| $(document).on('input change', '#gls-pickup-info-data', function() { | |
| checkShippingMethod(); | |
| }); | |
| // Listen to GLS map change events | |
| $(document).on('change', '.inchoo-gls-map', function() { | |
| setTimeout(function() { | |
| checkShippingMethod(); | |
| }, 100); | |
| setTimeout(function() { | |
| checkShippingMethod(); | |
| }, 300); | |
| setTimeout(function() { | |
| checkShippingMethod(); | |
| }, 600); | |
| }); | |
| // Watch for GLS pickup info div changes | |
| var glsPickupInfoObserver = new MutationObserver(function() { | |
| setTimeout(function() { | |
| checkShippingMethod(); | |
| }, 100); | |
| }); | |
| var glsPickupInfoElement = $('#gls-pickup-info')[0]; | |
| if (glsPickupInfoElement) { | |
| glsPickupInfoObserver.observe(glsPickupInfoElement, { | |
| childList: true, | |
| characterData: true, | |
| subtree: true, | |
| attributes: true | |
| }); | |
| } | |
| $(document.body).on('updated_checkout', function() { | |
| setTimeout(function() { | |
| var packetaInfoElement = $('.packeta-widget-info')[0]; | |
| if (packetaInfoElement && !packetaInfoElement.hasAttribute('data-observed')) { | |
| packetaInfoObserver.observe(packetaInfoElement, { | |
| childList: true, | |
| characterData: true, | |
| subtree: true | |
| }); | |
| packetaInfoElement.setAttribute('data-observed', 'true'); | |
| } | |
| var glsDataElement = $('#gls-pickup-info-data')[0]; | |
| if (glsDataElement && !glsDataElement.hasAttribute('data-observed')) { | |
| glsDataObserver.observe(glsDataElement, { | |
| attributes: true, | |
| attributeFilter: ['value'] | |
| }); | |
| glsDataElement.setAttribute('data-observed', 'true'); | |
| } | |
| var glsPickupInfoElement = $('#gls-pickup-info')[0]; | |
| if (glsPickupInfoElement && !glsPickupInfoElement.hasAttribute('data-observed')) { | |
| glsPickupInfoObserver.observe(glsPickupInfoElement, { | |
| childList: true, | |
| characterData: true, | |
| subtree: true, | |
| attributes: true | |
| }); | |
| glsPickupInfoElement.setAttribute('data-observed', 'true'); | |
| } | |
| checkShippingMethod(); | |
| }, 500); | |
| }); | |
| } | |
| $(document).ready(function() { | |
| bindShippingEvents(); | |
| checkShippingMethod(); | |
| }); | |
| })(jQuery); | |
| </script> | |
| <?php | |
| } | |
| } | |
| new WFACP_Custom_Shipping_Method_Compatibility(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment