Skip to content

Commit

Permalink
Woo Analytics: prevent accessing undefined wp.hooks on checkout (#36560)
Browse files Browse the repository at this point in the history
* Add checks for wp.hooks before accessing on checkout

* Add changelog

* bump version

---------

Co-authored-by: Jeremy Herve <[email protected]>
  • Loading branch information
opr and jeherve authored Apr 3, 2024
1 parent b0bbec5 commit 41890da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed a JavaScript error when accessing the Shortcode checkout with WooCommerce Analytics enabled
16 changes: 9 additions & 7 deletions projects/packages/woocommerce-analytics/src/class-universal.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,16 @@ function ( $payment_gateway ) {
if ( true === cartItem_{$cart_item_key}_logged ) {
return;
}
wp.hooks.addAction( 'wcpay.payment-request.availability', 'wcpay', function ( args ) {
properties.express_checkout = args.paymentRequestType;
} );
properties.checkout_page_contains_checkout_block = '0';
properties.checkout_page_contains_checkout_shortcode = '1';
if ( typeof wp !== 'undefined' && typeof wp.hooks !== 'undefined' && typeof wp.hooks.addAction === 'function' ) {
wp.hooks.addAction( 'wcpay.payment-request.availability', 'wcpay', function ( args ) {
properties.express_checkout = args.paymentRequestType;
} );
}
properties.checkout_page_contains_checkout_block = '0';
properties.checkout_page_contains_checkout_shortcode = '1';
_wca.push( properties );
cartItem_{$cart_item_key}_logged = true;
_wca.push( properties );
cartItem_{$cart_item_key}_logged = true;
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Woocommerce_Analytics {
/**
* Package version.
*/
const PACKAGE_VERSION = '0.1.2';
const PACKAGE_VERSION = '0.1.3-alpha';

/**
* Initializer.
Expand Down

0 comments on commit 41890da

Please sign in to comment.