2020-04-06 00:27:45 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Order Tracking
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tracks
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class adds actions to track usage of a WooCommerce Order.
|
|
|
|
*/
|
|
|
|
class WC_Order_Tracking {
|
2020-04-06 20:10:09 +00:00
|
|
|
|
2020-04-06 00:27:45 +00:00
|
|
|
/**
|
|
|
|
* Init tracking.
|
|
|
|
*/
|
|
|
|
public function init() {
|
|
|
|
add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'track_order_viewed' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks event when an order is viewed.
|
|
|
|
*
|
2020-04-08 09:56:18 +00:00
|
|
|
* @param WC_Order $order Order.
|
2020-04-06 00:27:45 +00:00
|
|
|
*/
|
|
|
|
public function track_order_viewed( $order ) {
|
2020-04-08 11:43:20 +00:00
|
|
|
if ( ! $order instanceof WC_Order || ! $order->get_id() ) {
|
2020-04-08 09:56:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-06 00:27:45 +00:00
|
|
|
$properties = array(
|
2020-04-06 20:10:09 +00:00
|
|
|
'current_status' => $order->get_status(),
|
2020-04-08 09:56:18 +00:00
|
|
|
'date_created' => $order->get_date_created() ? $order->get_date_created()->format( DateTime::ATOM ) : '',
|
2020-04-06 20:10:09 +00:00
|
|
|
'payment_method' => $order->get_payment_method(),
|
2020-04-06 00:27:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
WC_Tracks::record_event( 'single_order_view', $properties );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|