2019-02-20 19:41:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Orders Tracking
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tracks
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class adds actions to track usage of WooCommerce Orders.
|
|
|
|
*/
|
|
|
|
class WC_Orders_Tracking {
|
|
|
|
/**
|
|
|
|
* Init tracking.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function init() {
|
|
|
|
add_action( 'woocommerce_order_status_changed', array( $this, 'track_order_status_change' ), 10, 3 );
|
|
|
|
add_action( 'load-edit.php', array( $this, 'track_orders_view' ), 10 );
|
2019-02-20 19:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks event when the Orders page is viewed.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_orders_view() {
|
2019-02-26 22:59:04 +00:00
|
|
|
if ( isset( $_GET['post_type'] ) && 'shop_order' === wp_unslash( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
2019-04-08 03:37:36 +00:00
|
|
|
|
|
|
|
// phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.ValidatedSanitizedInput
|
|
|
|
$properties = array(
|
|
|
|
'status' => isset( $_GET['post_status'] ) ? sanitize_text_field( $_GET['post_status'] ) : 'all',
|
|
|
|
);
|
|
|
|
// phpcs:enable
|
|
|
|
|
|
|
|
WC_Tracks::record_event( 'orders_view', $properties );
|
2019-02-20 19:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks event when an order status is changed.
|
|
|
|
*
|
|
|
|
* @param int $id Order id.
|
|
|
|
* @param string $previous_status the old WooCommerce order status.
|
|
|
|
* @param string $next_status the new WooCommerce order status.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_order_status_change( $id, $previous_status, $next_status ) {
|
2019-02-20 19:41:06 +00:00
|
|
|
$order = wc_get_order( $id );
|
|
|
|
$date = $order->get_date_created();
|
|
|
|
|
|
|
|
$properties = array(
|
|
|
|
'order_id' => $id,
|
|
|
|
'next_status' => $next_status,
|
|
|
|
'previous_status' => $previous_status,
|
|
|
|
'date_created' => $date->date( 'Y-m-d' ),
|
|
|
|
);
|
|
|
|
|
|
|
|
WC_Tracks::record_event( 'orders_edit_status_change', $properties );
|
|
|
|
}
|
|
|
|
}
|