Created
July 7, 2026 08:03
-
-
Save xlplugins/3d66dd6fda6915420fadc5b62b5c8884 to your computer and use it in GitHub Desktop.
Master checkbox for all orderbump show hide
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
| /** | |
| * Plugin Name: FK Order Bumps — master show/hide toggle | |
| * Description: Adds one master checkbox that shows/hides ALL FunnelKit order bumps at once. | |
| * Unchecking it also removes any added bump (via WFOB's own flow) and refreshes the | |
| * order review, and the final state is saved on the order for later inspection. | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| /** | |
| * Persist the toggle state on the order + show it on the admin order screen. | |
| */ | |
| add_action( 'woocommerce_checkout_create_order', function ( $order ) { | |
| // Checkout submission is already nonce-verified by WooCommerce core. | |
| $state = isset( $_POST['fk_bump_master_state'] ) ? sanitize_text_field( wp_unslash( $_POST['fk_bump_master_state'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| if ( '' !== $state ) { | |
| $order->update_meta_data( '_fk_bump_master_shown', ( '1' === $state ) ? 'yes' : 'no' ); | |
| } | |
| }, 10, 1 ); | |
| add_action( 'woocommerce_admin_order_data_after_order_details', function ( $order ) { | |
| $val = $order->get_meta( '_fk_bump_master_shown' ); | |
| if ( '' !== $val ) { | |
| echo '<p><strong>' . esc_html__( 'Special offers toggle', 'woocommerce' ) . ':</strong> ' . esc_html( $val ) . '</p>'; | |
| } | |
| } ); | |
| /** | |
| * Front-end control. | |
| */ | |
| add_action( 'wp_footer', function () { | |
| if ( is_admin() ) { | |
| return; | |
| } | |
| ?> | |
| <style> | |
| label.fk-bump-master{display:inline-flex!important;align-items:center;gap:9px;margin:14px 0;padding:10px 14px; | |
| border:1px solid #e2e2e2;border-radius:6px;background:#fafafa;cursor:pointer;font-weight:600;line-height:1;box-sizing:border-box;} | |
| /* Real checkbox, but reset Aero's styling and draw our own (ID out-specifies theme rules) */ | |
| input#fk_bump_master_toggle{-webkit-appearance:none!important;appearance:none!important; | |
| width:18px!important;height:18px!important;min-width:18px!important;margin:0!important;padding:0!important; | |
| border:2px solid #9a9a9a!important;border-radius:4px!important;background:#fff!important; | |
| position:relative!important;opacity:1!important;box-shadow:none!important;outline:none!important; | |
| flex:0 0 auto!important;cursor:pointer;box-sizing:border-box!important;} | |
| input#fk_bump_master_toggle:checked{background:#2f9e44!important;border-color:#2f9e44!important;} | |
| input#fk_bump_master_toggle:checked::after{content:"";position:absolute;left:4px;top:0; | |
| width:6px;height:11px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg);box-sizing:border-box;} | |
| </style> | |
| <script> | |
| (function ($) { | |
| // ---- config ---- | |
| var LABEL = 'Show special offers'; | |
| var START_VISIBLE = true; // false = bumps hidden until checked (reveal style) | |
| var INSERT_AFTER = ''; // '' = right above first bump; or a selector to place it AFTER, e.g. '#payment' | |
| // ---------------- | |
| var ID = 'fk_bump_master_toggle'; | |
| var visible = START_VISIBLE; | |
| function boxes() { | |
| return $('.wfob_wrapper[data-wfob-id]').map(function () { | |
| var $w = $(this), $outer = $w.closest('.wfob_wrap_start'); | |
| return ($outer.length ? $outer : $w).get(0); | |
| }); | |
| } | |
| // Mirror the state into a hidden field inside the checkout form so it submits with the order. | |
| function syncHidden() { | |
| var $form = $('form.checkout, #wfacp_checkout_form, form.woocommerce-checkout').first(); | |
| if (!$form.length) { return; } | |
| var $h = $('#fk_bump_master_state'); | |
| if (!$h.length) { | |
| $h = $('<input type="hidden" id="fk_bump_master_state" name="fk_bump_master_state">'); | |
| $form.append($h); | |
| } | |
| $h.val(visible ? '1' : '0'); | |
| } | |
| // Remove any currently-added bump through WFOB's own flow (queues remove_order_bump + update_checkout). | |
| function removeAddedBumps() { | |
| $('.wfob_bump').each(function () { | |
| var $b = $(this); | |
| var $cb = $b.find('.wfob_bump_product:not(.wfob_choose_variation)'); | |
| if ($cb.length) { // checkbox layouts | |
| if ($cb.is(':checked')) { $cb.prop('checked', false).trigger('change'); } | |
| return; | |
| } | |
| var $rm = $b.find('.wfob_l3_f_btn.wfob_btn_remove.wfob_item_present'); // button layouts | |
| if ($rm.length) { $rm.trigger('click'); } | |
| }); | |
| } | |
| function applyState() { | |
| var $boxes = $(boxes()); | |
| if ($boxes.length === 0) { return; } | |
| visible ? $boxes.show() : $boxes.hide(); | |
| $('#' + ID).prop('checked', visible); | |
| syncHidden(); | |
| } | |
| function ensureMaster() { | |
| var $boxes = $(boxes()); | |
| if ($boxes.length === 0) { return; } | |
| if ($('#' + ID).length === 0) { | |
| var html = | |
| '<label class="fk-bump-master" for="' + ID + '">' + | |
| '<input type="checkbox" id="' + ID + '">' + | |
| '<span class="fk-bump-text">' + LABEL + '</span>' + | |
| '</label>'; | |
| var $anchor = INSERT_AFTER ? $(INSERT_AFTER).last() : $(); | |
| if ($anchor.length) { $anchor.after(html); } else { $boxes.first().before(html); } | |
| } | |
| applyState(); | |
| } | |
| $(document.body).on('change', '#' + ID, function () { | |
| visible = $(this).is(':checked'); | |
| if (!visible) { removeAddedBumps(); } // hiding also removes added bumps + refreshes order review | |
| applyState(); | |
| }); | |
| $(function () { ensureMaster(); }); | |
| $(document.body).on('updated_checkout', function () { ensureMaster(); }); | |
| })(jQuery); | |
| </script> | |
| <?php | |
| }, 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment