Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/Integrations/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
Loading