Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Last active February 27, 2026 14:02
Show Gist options
  • Select an option

  • Save xlplugins/2274e6ad96c118c8b32bbd700f095c67 to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/2274e6ad96c118c8b32bbd700f095c67 to your computer and use it in GitHub Desktop.
custom checkbox for offer page
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$allowed_offer_ids = array( 123 , 2487 );
add_action( 'wfocu_add_custom_html_above_accept_button', function( $product_id, $product_key ) use ( $allowed_offer_ids ) {
$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;
}
?>
<div class="wfocu-offer-checkbox-wrapper" data-product-key="<?php echo esc_attr( $product_key ); ?>">
<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
}, 25, 2 );
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 key = btn.getAttribute('data-key');
var wrap = document.querySelector('.wfocu-offer-checkbox-wrapper[data-product-key="'+key+'"]');
if(!wrap) return;
var cb = wrap.querySelector('.wfocu-offer-checkbox');
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