Skip to content

Commit 5a9340f

Browse files
authored
Merge pull request #249 from plausible/track_wc_direct_link_add_to_cart
Fixed: run track_direct_add_to_cart before WC's add to cart action in case it redirects.
2 parents a7d6b18 + 4adfa52 commit 5a9340f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Integrations/WooCommerce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ private function init( $init ) {
7171
add_action( 'woocommerce_after_add_to_cart_form', [ $this, 'track_add_to_cart_on_product_page' ] );
7272
add_action( 'woocommerce_store_api_validate_add_to_cart', [ $this, 'track_add_to_cart' ], 10, 2 );
7373
add_action( 'woocommerce_ajax_added_to_cart', [ $this, 'track_ajax_add_to_cart' ] );
74-
/** @see \WC_Form_Handler::add_to_cart_action() runs on priority 20. */
75-
add_action( 'wp_loaded', [ $this, 'track_direct_add_to_cart' ], 21 );
74+
/** @see \WC_Form_Handler::add_to_cart_action() runs on priority 20. We need to run before that, in case redirect is enabled. */
75+
add_action( 'wp_loaded', [ $this, 'track_direct_add_to_cart' ], 19 );
7676
add_action( 'woocommerce_remove_cart_item', [ $this, 'track_remove_cart_item' ], 10, 2 );
7777
add_action( 'wp_head', [ $this, 'track_entered_checkout' ] );
7878
add_action( 'woocommerce_thankyou', [ $this, 'track_purchase' ] );

0 commit comments

Comments
 (0)