|
add_action( 'wp_head', function () { |
|
if ( ! function_exists( 'is_checkout' ) || ! is_checkout() ) { |
|
return; |
|
} |
|
?> |
|
<script> |
|
( function () { |
|
/* Shared bootstrap (same in both FunnelKit Stripe express snippets): lets each snippet hook express buttons. */ |
|
window.fkwcsExpressHooks = window.fkwcsExpressHooks || []; |
|
if ( ! window.fkwcsExpressHooksReady ) { |
|
window.fkwcsExpressHooksReady = true; |
|
var wrapElements = function ( elements ) { |
|
return new Proxy( elements, { get: function ( t, key ) { |
|
var value = Reflect.get( t, key ); |
|
if ( 'create' !== key ) { return 'function' === typeof value ? value.bind( t ) : value; } |
|
return function ( type, options ) { |
|
var el = t.create( type, options ); |
|
if ( 'expressCheckout' !== type ) { return el; } |
|
window.fkwcsExpressHooks.forEach( function ( hook ) { el = hook( el, options || {} ); } ); |
|
return el; |
|
}; |
|
} } ); |
|
}; |
|
window.fkwcsGetStripe = function ( pubKey, options ) { |
|
window.fkwcsStripeInstances = window.fkwcsStripeInstances || {}; |
|
if ( ! window.fkwcsStripeInstances[ pubKey ] ) { |
|
var stripe = Stripe( pubKey, options ); |
|
window.fkwcsStripeInstances[ pubKey ] = new Proxy( stripe, { get: function ( t, key ) { |
|
var value = Reflect.get( t, key ); |
|
if ( 'elements' === key ) { return function () { return wrapElements( t.elements.apply( t, arguments ) ); }; } |
|
return 'function' === typeof value ? value.bind( t ) : value; |
|
} } ); |
|
} |
|
return window.fkwcsStripeInstances[ pubKey ]; |
|
}; |
|
} |
|
|
|
var reveal = function ( target ) { |
|
var $slot = jQuery( target ).closest( '[id^="wfacp_smart_button_fkwcs"]' ); |
|
if ( ! $slot.length || 'yes' !== $slot.attr( 'data-fkwcs-available' ) ) { |
|
return; |
|
} |
|
jQuery( '#wfacp_smart_buttons' ).addClass( 'wfacp_smart_buttons_active' ).show(); |
|
$slot.show().css( 'display', 'block' ).closest( '.wfacp_smart_button_container' ).show(); |
|
$slot.find( '.fkwcs_smart_buttons' ).show().css( { display: 'block', visibility: 'visible' } ); |
|
$slot.find( '.fkwcs_smart_button_trigger' ).addClass( 'hide' ).hide(); |
|
}; |
|
window.fkwcsExpressHooks.push( function ( el ) { |
|
var target = null; |
|
/* Runs after FunnelKit Stripe's own ready handler has marked the slot available. */ |
|
el.on( 'ready', function () { setTimeout( function () { if ( target ) { reveal( target ); } }, 0 ); } ); |
|
return new Proxy( el, { get: function ( t, key ) { |
|
if ( 'mount' === key ) { |
|
return function ( selector ) { target = selector; return t.mount( selector ); }; |
|
} |
|
var value = Reflect.get( t, key ); |
|
return 'function' === typeof value ? value.bind( t ) : value; |
|
} } ); |
|
} ); |
|
} )(); |
|
</script> |
|
<?php |
|
}, 1 ); |