-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathclass-abstract-integration.php
More file actions
154 lines (130 loc) · 2.97 KB
/
class-abstract-integration.php
File metadata and controls
154 lines (130 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* Abstract Class
*/
abstract class WCCT_Integration {
/**
* Store integration's id
*
* @var [type]
*/
protected $id;
/**
* Store integration's name
*
* @var string
*/
protected $name;
/**
* Check enable
*
* @var boolean
*/
protected $enabled;
/**
* Store integration's settings
*
* @var array
*/
protected $settings = array();
/**
* Store all supported features
*
* @var array
*/
protected $supports = array();
/**
* Get settings for all integration
*
* @return array
*/
abstract public function get_settings();
/**
* Enqueue integration script
*
* @return void
*/
abstract public function enqueue_script();
/**
* Get the integration id
*
* @return [type] [description]
*/
public function get_id() {
return $this->id;
}
/**
* Get the integration name
* Lazy translation so that we don't trigger autoload of the woocommerce-conversion-tracking textdomain
*
* @return string
*/
public function get_name() {
return __( $this->name, 'woocommerce-conversion-tracking' );
}
/**
* Check the integration enable or not
*
* @return boolean
*/
public function is_enabled() {
$settings = $this->get_integration_settings();
if ( $settings && wc_string_to_bool($settings[ 'enabled' ]) ) {
return true;
}
return false;
}
/**
* Check if an event is enabled
*
* @param string $event
*
* @return boolean
*/
public function event_enabled( $event ) {
$settings = $this->get_integration_settings();
if ( isset( $settings[0]['events'] ) && array_key_exists( $event, $settings[0]['events'] ) && $settings[0]['events'][ $event ] == 'on' ) {
return true;
}
return false;
}
/**
* Integration settings get options
*
* @return array|false
*/
public function get_integration_settings() {
$integration_settings = get_option( 'wcct_settings', array() );
if ( isset( $integration_settings[ $this->id ] ) ) {
return $integration_settings[ $this->id ];
}
return false;
}
/**
* Check feattures
*
* @param array $feature
*
* @return boolean
*/
public function supports( $feature ) {
if ( in_array( $feature, $this->supports ) ) {
return true;
}
return false;
}
/**
* Helper function to iterate through a cart and gather all content ids
*
* @param array $cart
*
* @return array
*/
protected function get_content_ids_from_cart( $cart ) {
$product_ids = array();
foreach ($cart as $item) {
$product_ids[] = $item['data']->get_id();
}
return $product_ids;
}
}