Completed
Push — try/tracks-store-stats ( b78a76...6e0574 )
by
unknown
16:11 queued 07:55
created

WC_Stats::get_cart_ids()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
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( 'woocommerce_init', array( $this, 'track' ) );
41
	}
42
43
	public function get_cart_ids( $item ) {
44
		return $item[ 'product_id' ];
45
	}
46
47
	public function track() {
48
		$cart = WC()->cart->get_cart();
49
		$cart_ids = array_map( array( $this, 'get_cart_ids' ), $cart );
50
51
		echo "<pre>";
52
		print_r( $cart_ids );
53
		echo "</pre>";
54
	}
55
}
56
57
WC_Stats::init();
58