Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save xlplugins/a115dfff6b5389ce4cd9a969eaf9ee2c to your computer and use it in GitHub Desktop.
WPC Product Bundles for WooCommerce by wpclever cart variation support
/**
* Product Addons + FKCart: Fix duplicate checkbox/switch IDs in quick view.
* Uses: prad_block_rendered (Product Addons), fkcart_cart_quick_view_open (FKCart).
*/
add_filter( 'prad_block_rendered', function ( $html, $block, $product_id ) {
if ( ! ( wp_doing_ajax() && ( ( isset( $_GET['wc-ajax'] ) && 'fkcart_quick_view' === $_GET['wc-ajax'] ) || ( isset( $_REQUEST['action'] ) && 'fkcart_quick_view' === $_REQUEST['action'] ) ) ) ) {
return $html;
}
if ( ! preg_match( '/data-bid=["\']([^"\']+)["\']/', $html, $m ) ) {
return $html;
}
return preg_replace( '/\b(id|for)="(' . preg_quote( $m[1], '/' ) . ')(\d*)"/', '$1="fkcart-$2$3"', $html );
}, 10, 3 );
add_action( 'wp_footer', function () {
?>
<script>
(function($) {
$(document.body).on('fkcart_cart_quick_view_open', function() {
$('#fkcart-modal .fkcart-drawer-content .prad-addons-wrapper').removeClass('prad-loading').find('.prad-loader').remove();
});
$(document).on('click', '#fkcart-modal .fkcart-drawer-content .prad-addons-wrapper label[for]', function(e) {
var $cb = $(this).closest('.prad-checkbox-item-wrapper, .prad-checkbox-item, .prad-switch-item').find('input[type="checkbox"]');
if ($cb.length) {
e.preventDefault();
$cb.prop('checked', !$cb.prop('checked')).trigger('change');
}
});
// Product Addons updates first #prad_selection in DOM (main form). Sync to drawer form before Update.
document.addEventListener('click', function(e) {
if (!$(e.target).closest('.fkcart-add-variant-product').length || !$(e.target).closest('#fkcart-modal').length) return;
var $f = $('#fkcart-modal .fkcart-drawer-content form.cart');
if ($f.length) {
$f.find('input[name="prad_selection"]').val($('#prad_selection').first().val() || '');
$f.find('input[name="prad_products_selection"]').val($('#prad_products_selection').first().val() || '');
}
}, true);
})(jQuery);
</script>
<?php
}, 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment