Last active
March 5, 2026 09:49
-
-
Save xlplugins/2274e6ad96c118c8b32bbd700f095c67 to your computer and use it in GitHub Desktop.
custom checkbox for offer page
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
| <?php | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| $allowed_offer_ids = array( 13079277 ); | |
| $wfocu_offer_checkbox_callback = function() use ( $allowed_offer_ids ) { | |
| static $done = false; | |
| if ( $done ) { | |
| return; | |
| } | |
| if ( ! class_exists( 'WFOCU_Core' ) || ! WFOCU_Core()->public || ! WFOCU_Core()->public->if_is_offer() ) { | |
| return; | |
| } | |
| $offer_id = WFOCU_Core()->data ? WFOCU_Core()->data->get( 'current_offer' ) : 0; | |
| $offer_id = $offer_id ?: get_the_ID(); | |
| if ( ! in_array( (int) $offer_id, $allowed_offer_ids, true ) ) { | |
| return; | |
| } | |
| $product_data = isset( WFOCU_Core()->template_loader->product_data->products ) ? WFOCU_Core()->template_loader->product_data->products : null; | |
| if ( ! $product_data ) { | |
| return; | |
| } | |
| $done = true; | |
| foreach ( $product_data as $product_key => $product ) { | |
| ?> | |
| <div class="wfocu-offer-checkbox-wrapper" data-product-key="<?php echo esc_attr( $product_key ); ?>" style="display:none;"> | |
| <label><input type="checkbox" class="wfocu-offer-checkbox" data-key="<?php echo esc_attr( $product_key ); ?>" /> I understand I purchase the subscription product.</label> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| <script> | |
| (function() { | |
| document.addEventListener('DOMContentLoaded', function() { | |
| document.querySelectorAll('.wfocu-offer-checkbox-wrapper[data-product-key]').forEach(function(wrap) { | |
| var key = wrap.getAttribute('data-product-key'); | |
| var btns = document.querySelectorAll('.wfocu_upsell[data-key="' + key + '"]'); | |
| btns.forEach(function(btn, idx) { | |
| var btnWrap = btn.closest('.bwf-btn-wrap') || btn.closest('.wfocu-accept-button'); | |
| var insertTarget = btnWrap ? btnWrap.parentNode : btn.parentNode; | |
| if (insertTarget) { | |
| var clone = idx === 0 ? wrap : wrap.cloneNode(true); | |
| clone.style.display = ''; | |
| insertTarget.insertBefore(clone, btnWrap || btn); | |
| } | |
| }); | |
| }); | |
| }); | |
| })(); | |
| </script> | |
| <?php | |
| }; | |
| add_action( 'wfocu_view_after_body_start', $wfocu_offer_checkbox_callback ); | |
| add_action( 'woofunnels_container_top', $wfocu_offer_checkbox_callback ); | |
| add_action( 'wp_footer', function() { | |
| if ( ! class_exists( 'WFOCU_Core' ) || ! WFOCU_Core()->public || ! WFOCU_Core()->public->if_is_offer() ) { | |
| return; | |
| } | |
| ?> | |
| <script> | |
| document.addEventListener('click', function(e){ | |
| var btn = e.target.closest('.wfocu_upsell'); | |
| if(!btn) return; | |
| var btnWrap = btn.closest('.bwf-btn-wrap') || btn.closest('.wfocu-accept-button'); | |
| var wrap = btnWrap ? btnWrap.previousElementSibling : null; | |
| if(!wrap || !wrap.classList.contains('wfocu-offer-checkbox-wrapper')) return; | |
| var cb = wrap.querySelector('.wfocu-offer-checkbox'); | |
| if(!cb) return; | |
| var prev = btn.previousElementSibling; | |
| if(prev && prev.classList.contains('wfocu-error')) prev.remove(); | |
| if(!cb.checked){ | |
| e.preventDefault(); | |
| e.stopImmediatePropagation(); | |
| btn.insertAdjacentHTML('beforebegin','<div class="wfocu-error" style="color:red;margin-bottom:6px;">Kindly accept the checkbox.</div>'); | |
| } | |
| }, true); | |
| </script> | |
| <?php | |
| }, 999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment