Completed
Push — try/tracks-store-stats ( 2ab7e3...b78a76 )
by
unknown
08:02
created

WC_Stats::init()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 5
nop 0
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7
class WC_Stats {
8
	/**
9
	 * @var Jetpack
10
	 **/
11
	private $jetpack;
12
13
	/**
14
	 * @var WC_Stats
15
	 **/
16
	private static $instance = null;
17
18
	static function init() {
19
		// Tracking only Site pages
20
		if ( is_admin() ) {
21
			return;
22
		}
23
		// Make sure Jetpack is installed and active
24
		if ( ! Jetpack::is_active() ) {
25
			return;
26
		}
27
		// Make sure WooCommerce is installed and active
28
		if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
29
			return;
30
		}
31
		if ( is_null( self::$instance ) ) {
32
			self::$instance = new WC_Stats();
33
		}
34
		return self::$instance;
35
	}
36
37
	public function __construct() {
38
		$this->jetpack = Jetpack::init();
39
40
		add_action( 'init', array( $this, 'track' ) );
41
	}
42
43
	public function track() {
44
		echo "<pre>";
45
//		print_r( WC_Data::get_data_store() );
46
//		print_r( WC_Cart::get_cart_from_session() );
47
//		print_r( WC()->cart->cart_contents );
48
		print_r( WC() );
49
//		global $wp_query;
50
//		print_r($wp_query);
51
		echo "</pre>";
52
	}
53
}
54
55
WC_Stats::init();
56