Skip to content

Commit

Permalink
if available, use is_created_via() to tell if an order is from the wp…
Browse files Browse the repository at this point in the history
… admin back office
  • Loading branch information
diosmosis committed Oct 25, 2023
1 parent 01080ae commit 349b4b4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions classes/WpMatomo/Ecommerce/Woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public function on_order( $order_id ) {
if ( ! $order ) {
return;
}

if ( $this->isOrderFromBackOffice( $order ) ) {
return;
}

$order_id_to_track = $order_id;
if ( method_exists( $order, 'get_order_number' ) ) {
$order_id_to_track = $order->get_order_number();
Expand Down Expand Up @@ -375,4 +380,14 @@ public function on_product_view() {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->wrap_script( $this->make_matomo_js_tracker_call( $params ) );
}

/**
* @param \WC_Order|\WC_Order_Refund $order
* @return bool
*/
private function isOrderFromBackOffice( $order ) {
// for recent versions of woocommerce (4.0+) use is_created_via(), otherwise default to is_admin() (which will provide false positives
// when using a theme that uses admin-ajax.php to add orders)
return method_exists( $order, 'is_created_via' ) ? $order->is_created_via( 'admin' ) : is_admin();
}
}

0 comments on commit 349b4b4

Please sign in to comment.