Created
April 21, 2026 05:53
-
-
Save xlplugins/b31ba0012cab8aeb3eec0d05359e254a to your computer and use it in GitHub Desktop.
Tropics fields — FunnelKit checkout
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
| add_action( | |
| 'wp_enqueue_scripts', | |
| static function () { | |
| if ( ! function_exists( 'is_checkout' ) || ! is_checkout() || is_order_received_page() ) { | |
| return; | |
| } | |
| /* FunnelKit not active — nothing to bridge. */ | |
| if ( ! class_exists( 'WFACP_Common' ) ) { | |
| return; | |
| } | |
| wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| wp_enqueue_style( | |
| 'tropics-mu-jui', | |
| 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/themes/smoothness/jquery-ui.min.css', | |
| array(), | |
| '1.13.2' | |
| ); | |
| wp_add_inline_style( 'tropics-mu-jui', '#ui-datepicker-div{z-index:100200!important;}' ); | |
| wp_register_script( 'tropics-mu-fk', false, array( 'jquery', 'jquery-ui-datepicker' ), '1.1.1', true ); | |
| wp_enqueue_script( 'tropics-mu-fk' ); | |
| $inline = <<<'JS' | |
| (function($){ | |
| function esc(s){return String(s||'').replace(/&/g,'&').replace(/"/g,'"').replace(/</g,'<').replace(/>/g,'>');} | |
| /** Only FunnelKit — native checkout uses theme JS only */ | |
| function fk(){return $('#wfacp_checkout_form').length>0;} | |
| function $w(){return $('input[name="wedding_date"],input[name="billing_wedding_date"],#wedding_date,#billing_wedding_date');} | |
| function $lg(){return $('select[name="w_select_option"],select[name="billing_w_select_option"],#w_select_option,#billing_w_select_option');} | |
| function hideCal(){try{$('#ui-datepicker-div').hide();$w().each(function(){if($(this).hasClass('hasDatepicker'))$(this).datepicker('hide');});}catch(e){}} | |
| function toggle(){var s=$lg().first();if(!s.length)return;var v=s.val(),g=$('#w_group_name_field,#billing_w_group_name_field'),q=$('#w_qty_of_orders_field,#billing_w_qty_of_orders_field');if(v==='Yes'){g.show().css('display','');q.show().css('display','');g.find('label span.optional').html('*');g.find('label span').addClass('required').removeClass('optional');}else{g.hide();q.hide();g.find('label span').addClass('optional').removeClass('required');g.find('label span.optional').html('(OPTIONAL)');}} | |
| function dp(){if(!fk()||typeof $.fn.datepicker!=='function')return;var t=new Date();$w().each(function(){var e=$(this);if(e.hasClass('hasDatepicker')){try{e.datepicker('destroy');}catch(x){}}e.datepicker({dateFormat:'yy-mm-dd',minDate:t,beforeShow:function(){setTimeout(function(){$('#ui-datepicker-div').css('z-index',100200);},0);},onSelect:function(){hideCal();$(this).blur();}});e.attr('autocomplete','off').attr('readonly',true);});} | |
| function bs(){if(window.tropicsShowTropicsModal)return;window.tropicsShowTropicsModal=function(){var el=document.getElementById('modal-tropics-global');if(!el)return;if(typeof bootstrap!=='undefined'&&bootstrap.Modal)bootstrap.Modal.getOrCreateInstance(el).show();else if($.fn.modal)$(el).modal('show');};window.tropicsHideTropicsModal=function(){var el=document.getElementById('modal-tropics-global');if(!el)return;if(typeof bootstrap!=='undefined'&&bootstrap.Modal){var i=bootstrap.Modal.getInstance(el);if(i)i.hide();}else if($.fn.modal)$(el).modal('hide');};} | |
| function pop(){if(!$('#modal-tropics-global').length||!fk())return;bs();$(document.body).off('click.trp','.tropics-popup').on('click.trp','.tropics-popup',function(e){e.preventDefault();var t=$(this),u=t.attr('data-href'),y=t.attr('data-href-type'),ti=t.attr('title')||'';if(y==='image'){$('#modal-tropics-global .modal-body .tropics-modal-container').html('<img src="'+esc(u)+'" alt="'+esc(ti)+'" >');if($('#modal-tropics-global').hasClass('show'))window.tropicsHideTropicsModal();window.tropicsShowTropicsModal();}else if(y==='pdf'){$('#modal-tropics-global .modal-body .tropics-modal-container').html('<iframe title="Pdf" src="'+esc(u)+'" style="width:800px!important;height:85vh;" frameborder="0"></iframe>');if($('#modal-tropics-global').hasClass('show'))window.tropicsHideTropicsModal();window.tropicsShowTropicsModal();}else{$('#modal-tropics-global .modal-body .tropics-modal-container').load(u,function(){if($('#modal-tropics-global').hasClass('show'))window.tropicsHideTropicsModal();window.tropicsShowTropicsModal();});}});} | |
| function run(){if(!fk())return;dp();toggle();pop();} | |
| $(function(){ | |
| if(!fk())return; | |
| run(); | |
| $(document.body).on('update_checkout',hideCal); | |
| $(document.body).on('updated_checkout',function(){setTimeout(run,50);}); | |
| $(document.body).on('change','select[name="w_select_option"],select[name="billing_w_select_option"],#w_select_option,#billing_w_select_option',toggle); | |
| $(document.body).on('select2:select','select[name="w_select_option"],select[name="billing_w_select_option"]',function(){setTimeout(toggle,0);}); | |
| }); | |
| })(jQuery); | |
| JS; | |
| wp_add_inline_script( 'tropics-mu-fk', $inline ); | |
| }, | |
| 999 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment