From 34ec28870f5114f5600af51634b394f9ebab1c41 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 23 Jun 2026 17:24:40 +0200 Subject: [PATCH 1/2] Fixed: if Permalinks > Custom Base was previously modified with WooCommerce enabled, the view-product goal would wrongfully get a 2nd leading slash. --- src/Integrations/WooCommerce.php | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Integrations/WooCommerce.php b/src/Integrations/WooCommerce.php index 7cf537a8..5d966515 100644 --- a/src/Integrations/WooCommerce.php +++ b/src/Integrations/WooCommerce.php @@ -33,7 +33,7 @@ public function __construct( $init = true ) { if ( is_multisite() ) { $uri = get_blog_details()->path . $uri; } else { - $uri = '/' . $uri; + $uri = '/' . trim( $uri, '/' ); } $this->event_goals = [ @@ -142,25 +142,6 @@ public function track_ajax_add_to_cart( $product_id ) { $this->track_add_to_cart( $product, $add_to_cart_data ); } - /** - * Track add to cart actions by direct link, e.g. ?product_type=download&add-to-cart=1&quantity=1 - * - * @return void - * - * @codeCoverageIgnore Because we can't test XHR here. - */ - public function track_direct_add_to_cart() { - if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( wp_unslash( $_REQUEST['add-to-cart'] ) ) ) { - return; - } - - $product_id = absint( wp_unslash( $_REQUEST['add-to-cart'] ) ); - $product = wc_get_product( $product_id ); - $quantity = isset( $_REQUEST['quantity'] ) ? absint( wp_unslash( $_REQUEST['quantity'] ) ) : 1; - - $this->track_add_to_cart( $product, [ 'id' => $product_id, 'quantity' => $quantity ] ); - } - /** * Track regular (i.e., interactivity API) add to cart events. * @@ -226,6 +207,25 @@ protected function get_wc_cart() { return WC()->cart; } + /** + * Track add to cart actions by direct link, e.g. ?product_type=download&add-to-cart=1&quantity=1 + * + * @return void + * + * @codeCoverageIgnore Because we can't test XHR here. + */ + public function track_direct_add_to_cart() { + if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( wp_unslash( $_REQUEST['add-to-cart'] ) ) ) { + return; + } + + $product_id = absint( wp_unslash( $_REQUEST['add-to-cart'] ) ); + $product = wc_get_product( $product_id ); + $quantity = isset( $_REQUEST['quantity'] ) ? absint( wp_unslash( $_REQUEST['quantity'] ) ) : 1; + + $this->track_add_to_cart( $product, [ 'id' => $product_id, 'quantity' => $quantity ] ); + } + /** * Tracks when a user enters the checkout process and sends event data to Plausible Analytics. * From 24a610bbfe228e2ee6b5c398f917c4c59088b57c Mon Sep 17 00:00:00 2001 From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:16:47 +0200 Subject: [PATCH 2/2] Fixed: if Permalinks > Custom Base was previously modified with WooCommerce enabled, the view-product goal would wrongfully get a 2nd leading slash. --- src/Integrations/WooCommerce.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Integrations/WooCommerce.php b/src/Integrations/WooCommerce.php index 5d966515..58f3a023 100644 --- a/src/Integrations/WooCommerce.php +++ b/src/Integrations/WooCommerce.php @@ -28,12 +28,12 @@ class WooCommerce { * @codeCoverageIgnore */ public function __construct( $init = true ) { - $uri = wc_get_permalink_structure()['product_base']; + $uri = trim( wc_get_permalink_structure()['product_base'], '/' ); if ( is_multisite() ) { $uri = get_blog_details()->path . $uri; } else { - $uri = '/' . trim( $uri, '/' ); + $uri = '/' . $uri; } $this->event_goals = [