Remove jQuery dependency from the checkout frontend
This commit is contained in:
parent
58f703211c
commit
dd66ba0d39
|
@ -1,4 +1,4 @@
|
||||||
( function ( $, wc_order_source_attribution ) {
|
( function ( wc_order_source_attribution ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const params = wc_order_source_attribution.params;
|
const params = wc_order_source_attribution.params;
|
||||||
|
@ -6,6 +6,8 @@
|
||||||
const cookieLifetime = Number( params.lifetime );
|
const cookieLifetime = Number( params.lifetime );
|
||||||
const sessionLength = Number( params.session );
|
const sessionLength = Number( params.session );
|
||||||
|
|
||||||
|
const $ = document.querySelector.bind( document );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flattens the sbjs.get object into a schema compatible object.
|
* Flattens the sbjs.get object into a schema compatible object.
|
||||||
*
|
*
|
||||||
|
@ -56,7 +58,7 @@
|
||||||
|
|
||||||
if ( sbjs.get ) {
|
if ( sbjs.get ) {
|
||||||
for( const [ key, value ] of Object.entries( wc_order_source_attribution.sbjsDataToSchema( sbjs.get ) ) ) {
|
for( const [ key, value ] of Object.entries( wc_order_source_attribution.sbjsDataToSchema( sbjs.get ) ) ) {
|
||||||
$( `input[name="${prefix}${key}"]` ).val( value );
|
$( `input[name="${prefix}${key}"]` ).value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -64,12 +66,16 @@
|
||||||
/**
|
/**
|
||||||
* Add source values to checkout.
|
* Add source values to checkout.
|
||||||
*/
|
*/
|
||||||
$( document.body ).on( 'init_checkout', () => { setFields(); } );
|
const previousInitCheckout = document.body.oninit_checkout;
|
||||||
|
document.body.oninit_checkout = () => {
|
||||||
|
setFields();
|
||||||
|
previousInitCheckout();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add source values to register.
|
* Add source values to register.
|
||||||
*/
|
*/
|
||||||
if ( $( '.woocommerce form.register' ).length ) {
|
if ( $( '.woocommerce form.register' ) !== null ) {
|
||||||
setFields();
|
setFields();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,4 +118,4 @@
|
||||||
// Run init.
|
// Run init.
|
||||||
wc_order_source_attribution.initOrderTracking();
|
wc_order_source_attribution.initOrderTracking();
|
||||||
|
|
||||||
}( jQuery, window.wc_order_source_attribution ) );
|
}( window.wc_order_source_attribution ) );
|
||||||
|
|
|
@ -190,7 +190,7 @@ class SourceAttributionController implements RegisterHooksInterface {
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'wc-order-source-attribution',
|
'wc-order-source-attribution',
|
||||||
plugins_url( "assets/js/frontend/order-source-attribution{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
|
plugins_url( "assets/js/frontend/order-source-attribution{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
|
||||||
array( 'jquery', 'sourcebuster-js' ),
|
array( 'sourcebuster-js' ),
|
||||||
Constants::get_constant( 'WC_VERSION' ),
|
Constants::get_constant( 'WC_VERSION' ),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue