fix: disable WC cart redirect, enable AJAX add-to-cart, fix double-click toggle bug
This commit is contained in:
@@ -70,35 +70,42 @@
|
||||
/**
|
||||
* Trigger the theme's minicart open mechanism.
|
||||
*
|
||||
* Strategy:
|
||||
* 1. Try clicking the first element matching the configured selector.
|
||||
* 2. If that element has no jQuery click handlers registered, dispatch
|
||||
* a native 'click' so themes that use addEventListener also fire.
|
||||
* Strategy (stops at the first approach that succeeds):
|
||||
* 1. Find the header cart button via the configured selector list and
|
||||
* fire ONE native click on it. Using native click (not jQuery trigger
|
||||
* + native) avoids the double-fire / toggle-closed bug.
|
||||
* 2. If no button is found, try to show the Shoptimizer cart panel
|
||||
* directly by toggling the body class the theme uses.
|
||||
* 3. Last resort: navigate to the cart URL.
|
||||
*
|
||||
* NOTE: never call both $el.trigger('click') AND el.click() — that
|
||||
* fires two events and the toggle cancels itself immediately.
|
||||
*/
|
||||
openMinicart: function () {
|
||||
// --- 1. Try clicking the configured header cart button ------------
|
||||
var selectors = ( cgkitFC.minicartTrigger || '' ).split( ',' );
|
||||
var $trigger = null;
|
||||
|
||||
for ( var i = 0; i < selectors.length; i++ ) {
|
||||
var $el = $( $.trim( selectors[ i ] ) ).first();
|
||||
if ( $el.length ) {
|
||||
$trigger = $el;
|
||||
break;
|
||||
// One native click – reaches both jQuery and native listeners.
|
||||
$el[ 0 ].click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $trigger && $trigger.length ) {
|
||||
// Fire both jQuery and native click so all listeners catch it.
|
||||
$trigger.trigger( 'click' );
|
||||
var nativeEl = $trigger.get( 0 );
|
||||
if ( nativeEl && typeof nativeEl.click === 'function' ) {
|
||||
nativeEl.click();
|
||||
}
|
||||
// --- 2. Shoptimizer direct panel toggle --------------------------
|
||||
// Shoptimizer opens its cart panel by adding the 'active' class to
|
||||
// .site-header-cart and showing the child .widget_shopping_cart.
|
||||
// Try that directly if we couldn't find the button.
|
||||
var $panel = $( '.site-header-cart' );
|
||||
if ( $panel.length ) {
|
||||
$panel.toggleClass( 'active' );
|
||||
$panel.find( '.widget_shopping_cart' ).toggleClass( 'cart-open' );
|
||||
return;
|
||||
}
|
||||
|
||||
// No trigger found → fall back to cart page
|
||||
// --- 3. Fall back to cart page -----------------------------------
|
||||
if ( cgkitFC.cartUrl ) {
|
||||
window.location.href = cgkitFC.cartUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user