PixelYourSite – Facebook Pixel (Events, WooCommerce & Easy Digital Downloads) - Version 5.3.0

Version Description

Download this release

Release Info

Developer PixelYourSite
Plugin Icon 128x128 PixelYourSite – Facebook Pixel (Events, WooCommerce & Easy Digital Downloads)
Version 5.3.0
Comparing to
See all releases

Code changes from version 5.2.1 to 5.3.0

facebook-pixel-master.php CHANGED
@@ -1,65 +1,65 @@
1
- <?php
2
- /*
3
- Plugin Name: PixelYourSite
4
- Description: Add the Facebook Pixel code into your Wordpress site and set up standard events with just a few clicks. Fully compatible with Woocommerce, purchase event included.
5
- Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
- Author: PixelYourSite
7
- Author URI: http://www.pixelyoursite.com
8
- Version: 5.2.1
9
- License: GPLv3
10
- WC requires at least: 2.6.0
11
- WC tested up to: 3.3.0
12
- */
13
-
14
- if ( ! defined( 'ABSPATH' ) ) {
15
- exit; // Exit if accessed directly.
16
- }
17
-
18
- define( 'PYS_FREE_VERSION', '5.2.1' );
19
-
20
- if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
21
-
22
- /**
23
- * Check whatever PixelYourSite PRO version activated.
24
- *
25
- * @return bool
26
- */
27
- function pys_is_pixelyoursite_pro_active() {
28
-
29
- if ( ! function_exists( 'is_plugin_active' ) ) {
30
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
31
- }
32
-
33
- return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
34
-
35
- }
36
-
37
- }
38
-
39
- if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
40
-
41
- register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
42
- function pys_free_plugin_activated() {
43
-
44
- if ( pys_is_pixelyoursite_pro_active() ) {
45
- wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
46
- 'back_link' => true,
47
- ) );
48
- }
49
-
50
- $options = get_option( 'pixel_your_site' );
51
-
52
- if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
53
-
54
- require_once 'inc/general.php';
55
- pys_initialize_settings();
56
-
57
- }
58
-
59
- }
60
-
61
- }
62
-
63
- if ( ! pys_is_pixelyoursite_pro_active() ) {
64
- require_once 'inc/general.php';
65
- }
1
+ <?php
2
+ /*
3
+ Plugin Name: PixelYourSite
4
+ Description: Add the Facebook Pixel code into your Wordpress site and set up standard events with just a few clicks. Fully compatible with Woocommerce, purchase event included.
5
+ Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
+ Author: PixelYourSite
7
+ Author URI: http://www.pixelyoursite.com
8
+ Version: 5.3.0
9
+ License: GPLv3
10
+ WC requires at least: 2.6.0
11
+ WC tested up to: 3.3.5
12
+ */
13
+
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit; // Exit if accessed directly.
16
+ }
17
+
18
+ define( 'PYS_FREE_VERSION', '5.3.0' );
19
+
20
+ if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
21
+
22
+ /**
23
+ * Check whatever PixelYourSite PRO version activated.
24
+ *
25
+ * @return bool
26
+ */
27
+ function pys_is_pixelyoursite_pro_active() {
28
+
29
+ if ( ! function_exists( 'is_plugin_active' ) ) {
30
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
31
+ }
32
+
33
+ return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
34
+
35
+ }
36
+
37
+ }
38
+
39
+ if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
40
+
41
+ register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
42
+ function pys_free_plugin_activated() {
43
+
44
+ if ( pys_is_pixelyoursite_pro_active() ) {
45
+ wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
46
+ 'back_link' => true,
47
+ ) );
48
+ }
49
+
50
+ $options = get_option( 'pixel_your_site' );
51
+
52
+ if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
53
+
54
+ require_once 'inc/general.php';
55
+ pys_initialize_settings();
56
+
57
+ }
58
+
59
+ }
60
+
61
+ }
62
+
63
+ if ( ! pys_is_pixelyoursite_pro_active() ) {
64
+ require_once 'inc/general.php';
65
+ }
inc/common.php CHANGED
@@ -1,1482 +1,1392 @@
1
- <?php
2
- /**
3
- * Common functions for both versions.
4
- */
5
-
6
- if ( ! defined( 'ABSPATH' ) ) {
7
- exit; // Exit if accessed directly.
8
- }
9
-
10
- /**
11
- * Check if WooCommerce plugin is installed and activated.
12
- */
13
- if( !function_exists( 'pys_is_woocommerce_active' ) ) {
14
-
15
- function pys_is_woocommerce_active() {
16
- return class_exists( 'WooCommerce' ) == true ? true : false;
17
- }
18
-
19
- }
20
-
21
- /**
22
- * Check if Easy Digital Downloads plugin is installed and activated.
23
- */
24
- if( !function_exists( 'pys_is_edd_active' ) ) {
25
-
26
- function pys_is_edd_active() {
27
- return class_exists( 'Easy_Digital_Downloads' ) == true ? true : false;
28
- }
29
-
30
- }
31
-
32
- if ( ! function_exists( 'pys_is_pcf_pro_active' ) ) {
33
-
34
- function pys_is_pcf_pro_active() {
35
- return class_exists( 'wpwoof_product_catalog' ) == true ? true : false;
36
- }
37
-
38
- }
39
-
40
- if( !function_exists( 'pys_get_option' ) ) {
41
-
42
- /**
43
- * Return option value.
44
- *
45
- * @param string $section Options section, eg. 'general', 'woo', etc.
46
- * @param string $option Option name
47
- * @param mixed|string $default Default option value
48
- *
49
- * @return mixed Option or default option value
50
- */
51
- function pys_get_option( $section, $option, $default = '' ) {
52
-
53
- $options = get_option( 'pixel_your_site' );
54
-
55
- return isset( $options[ $section ][ $option ] ) ? $options[ $section ][ $option ] : $default;
56
-
57
- }
58
-
59
- }
60
-
61
- if( !function_exists( 'pys_checkbox_state' ) ) {
62
-
63
- /**
64
- * @param string $section Option section name
65
- * @param string $option Option name
66
- * @param bool $echo Echo or return value
67
- * @param int $checked Value to state compare
68
- *
69
- * @return string
70
- */
71
- function pys_checkbox_state( $section, $option, $echo = true, $checked = 1 ) {
72
-
73
- $options = get_option( 'pixel_your_site' );
74
-
75
- if ( isset( $options[ $section ][ $option ] ) ) {
76
- $value = $options[ $section ][ $option ] == $checked ? 'checked' : '';
77
- } else {
78
- $value = '';
79
- }
80
-
81
- if( $echo ) {
82
- echo $value;
83
- }
84
-
85
- return $value;
86
-
87
- }
88
-
89
- }
90
-
91
- if ( ! function_exists( 'pys_checkbox' ) ) {
92
-
93
- /**
94
- * Echos checkbox input.
95
- *
96
- * @param string $section Input section name
97
- * @param string $option Input option name
98
- * @param string $classes Class names (optional)
99
- * @param int $value Input value (optional)
100
- */
101
- function pys_checkbox( $section, $option, $classes = '', $value = 1 ) {
102
-
103
- $state = pys_checkbox_state( $section, $option, false, $value );
104
- $value = esc_attr( $value );
105
-
106
- echo "<input type='checkbox' value='$value' name='pys[$section][$option]' class='$classes' $state>";
107
-
108
- }
109
-
110
- }
111
-
112
- if ( ! function_exists( 'pys_text_field' ) ) {
113
-
114
- /**
115
- * Echos text input.
116
- *
117
- * @param string $section Input section name
118
- * @param string $option Input option name
119
- */
120
- function pys_text_field( $section, $option ) {
121
-
122
- $value = pys_get_option( $section, $option );
123
- $value = esc_attr( $value );
124
-
125
- echo "<input type='text' value='$value' name='pys[$section][$option]'>";
126
-
127
- }
128
-
129
- }
130
-
131
- if ( ! function_exists( 'pys_radio_box' ) ) {
132
-
133
- /**
134
- * Echos radio box input.
135
- *
136
- * @param string $section Input section name
137
- * @param string $option Input option name
138
- * @param string $value Option value
139
- */
140
- function pys_radio_box( $section, $option, $value ) {
141
-
142
- $state = pys_radio_state( $section, $option, $value );
143
- echo "<input type='radio' value='$value' name='pys[$section][$option]' $state>";
144
-
145
- }
146
-
147
- }
148
-
149
- /**
150
- * Return radio box state.
151
- */
152
- if( !function_exists( 'pys_radio_state' ) ) {
153
-
154
- function pys_radio_state( $section, $option, $value ) {
155
-
156
- $options = get_option( 'pixel_your_site' );
157
-
158
- if ( isset( $options[ $section ][ $option ] ) ) {
159
-
160
- return $options[ $section ][ $option ] == $value ? 'checked' : '';
161
-
162
- } else {
163
-
164
- $defaults = pys_get_default_options();
165
- return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
166
-
167
- }
168
-
169
- }
170
-
171
- }
172
-
173
- /**
174
- * Facebook Pixel Event types options html.
175
- */
176
- if( !function_exists( 'pys_event_types_select_options' ) ) {
177
-
178
- function pys_event_types_select_options( $current = null, $full = true ) {
179
- ?>
180
-
181
- <option <?php selected( null, $current ); ?> disabled>Select Type</option>
182
- <option <?php selected( 'ViewContent', $current ); ?> value="ViewContent">ViewContent</option>
183
-
184
- <?php if ( $full ) : ?>
185
-
186
- <option <?php selected( 'Search', $current ); ?> value="Search">Search</option>
187
-
188
- <?php endif; ?>
189
-
190
- <option <?php selected( 'AddToCart', $current ); ?> value="AddToCart">AddToCart</option>
191
- <option <?php selected( 'AddToWishlist', $current ); ?> value="AddToWishlist">AddToWishlist</option>
192
- <option <?php selected( 'InitiateCheckout', $current ); ?> value="InitiateCheckout">InitiateCheckout</option>
193
- <option <?php selected( 'AddPaymentInfo', $current ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
194
- <option <?php selected( 'Purchase', $current ); ?> value="Purchase">Purchase</option>
195
- <option <?php selected( 'Lead', $current ); ?> value="Lead">Lead</option>
196
- <option <?php selected( 'CompleteRegistration', $current ); ?> value="CompleteRegistration">CompleteRegistration</option>
197
-
198
- <?php if ( $full ) : ?>
199
-
200
- <option disabled></option>
201
- <option <?php selected( 'CustomEvent', $current ); ?> value="CustomEvent">Custom event</option>
202
- <option <?php selected( 'CustomCode', $current); ?> value="CustomCode">Custom event code</option>
203
-
204
- <?php endif; ?>
205
-
206
- <?php
207
- }
208
-
209
- }
210
-
211
- /**
212
- * Current Page Full URL without trailing slash
213
- */
214
- if( !function_exists( 'pys_get_current_url' ) ) {
215
-
216
- function pys_get_current_url() {
217
-
218
- $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
219
- $current_url = rtrim( $current_url, '/' );
220
-
221
- return $current_url;
222
-
223
- }
224
-
225
- }
226
-
227
- /**
228
- * Returns relative path without protocol, host, slashes.
229
- */
230
- if( !function_exists( 'pys_get_relative_path' ) ) {
231
-
232
- function pys_get_relative_path( $url ) {
233
-
234
- $host = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', home_url() );
235
-
236
- $url = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', $url );
237
- $url = str_replace( $host, '', $url );
238
-
239
- $url = trim( $url );
240
- $url = ltrim( $url, '/' );
241
- $url = rtrim( $url, '/' );
242
-
243
- return $url;
244
-
245
- }
246
-
247
- }
248
-
249
- /**
250
- * Check if needle URL (full or relative) matches with current.
251
- */
252
- if( !function_exists( 'pys_match_url' ) ) {
253
-
254
- function pys_match_url( $match_url, $current_url = '' ) {
255
-
256
- // use current url by default
257
- if ( ! isset( $current_url ) || empty( $current_url ) ) {
258
- $current_url = pys_get_current_url();
259
- }
260
-
261
- $current_url = pys_get_relative_path( $current_url );
262
- $match_url = pys_get_relative_path( $match_url );
263
-
264
- if ( substr( $match_url, - 1 ) == '*' ) {
265
- // if match_url ends with wildcard
266
-
267
- $match_url = rtrim( $match_url, '*' );
268
-
269
- if ( pys_startsWith( $current_url, $match_url ) ) {
270
- return true;
271
- }
272
-
273
- } else {
274
- // exact url
275
-
276
- if ( $current_url == $match_url ) {
277
- return true;
278
- }
279
-
280
- }
281
-
282
- return false;
283
-
284
- }
285
-
286
- }
287
-
288
- if( !function_exists( 'pys_startsWith' ) ) {
289
-
290
- function pys_startsWith( $haystack, $needle ) {
291
- // search backwards starting from haystack length characters from the end
292
- return $needle === "" || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
293
- }
294
-
295
- }
296
-
297
- if( !function_exists( 'pys_endsWith' ) ) {
298
-
299
- function pys_endsWith( $haystack, $needle ) {
300
- // search forward starting from end minus needle length characters
301
- return $needle === "" || ( ( $temp = strlen( $haystack ) - strlen( $needle ) ) >= 0 && strpos( $haystack, $needle, $temp ) !== false );
302
- }
303
-
304
- }
305
-
306
- if( !function_exists( 'pys_currency_options' ) ) {
307
-
308
- function pys_currency_options( $current = 'USD' ) {
309
-
310
- $currencies = apply_filters( 'pys_currencies_list', array(
311
- 'AUD' => 'Australian Dollar',
312
- 'BRL' => 'Brazilian Real',
313
- 'CAD' => 'Canadian Dollar',
314
- 'CZK' => 'Czech Koruna',
315
- 'DKK' => 'Danish Krone',
316
- 'EUR' => 'Euro',
317
- 'HKD' => 'Hong Kong Dollar',
318
- 'HUF' => 'Hungarian Forint',
319
- 'IDR' => 'Indonesian Rupiah',
320
- 'ILS' => 'Israeli New Sheqel',
321
- 'JPY' => 'Japanese Yen',
322
- 'KRW' => 'Korean Won',
323
- 'MYR' => 'Malaysian Ringgit',
324
- 'MXN' => 'Mexican Peso',
325
- 'NOK' => 'Norwegian Krone',
326
- 'NZD' => 'New Zealand Dollar',
327
- 'PHP' => 'Philippine Peso',
328
- 'PLN' => 'Polish Zloty',
329
- 'RON' => 'Romanian Leu',
330
- 'GBP' => 'Pound Sterling',
331
- 'SGD' => 'Singapore Dollar',
332
- 'SEK' => 'Swedish Krona',
333
- 'CHF' => 'Swiss Franc',
334
- 'TWD' => 'Taiwan New Dollar',
335
- 'THB' => 'Thai Baht',
336
- 'TRY' => 'Turkish Lira',
337
- 'USD' => 'U.S. Dollar',
338
- 'ZAR' => 'South African Rands'
339
- ) );
340
-
341
- foreach( $currencies as $symbol => $name ) {
342
- echo '<option ' . selected( $symbol, $current, false ) . ' value="' . esc_attr( $symbol ) . '">' . esc_html( $name ) . '</option>';
343
- }
344
-
345
- }
346
-
347
- }
348
-
349
- /**
350
- * Extract Object taxonomies list.
351
- */
352
- if( !function_exists( 'pys_get_content_taxonomies' ) ) {
353
-
354
- function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
355
-
356
- $post_id = isset( $post_id ) ? $post_id : get_the_ID();
357
- $terms = get_the_terms( $post_id, $taxonomy );
358
-
359
- if ( is_wp_error( $terms ) || empty ( $terms ) ) {
360
- return false;
361
- }
362
-
363
- $list = array();
364
-
365
- foreach( $terms as $term ) {
366
- $list[ $term->term_id ] = html_entity_decode( $term->name );
367
- }
368
-
369
- return implode( ', ', $list );
370
-
371
- }
372
-
373
- }
374
-
375
- if( !function_exists( 'pys_add_event' ) ) {
376
-
377
- /**
378
- * Add event with params to global events list.
379
- *
380
- * @param string $event Event name, eg. "PageView"
381
- * @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
382
- * @param int $delay Optional. If set, event will be fired with desired delay in seconds.
383
- */
384
- function pys_add_event( $event, $params = array(), $delay = 0 ) {
385
- global $pys_events;
386
-
387
- $params = apply_filters( 'pys_event_params', $params, $event );
388
-
389
- $sanitized = array();
390
-
391
- // sanitize param names and its values
392
- foreach ( $params as $name => $value ) {
393
-
394
- // skip empty but not zero values
395
- if ( empty( $value ) && ! is_numeric( $value ) ) {
396
- continue;
397
- }
398
-
399
- $key = esc_js( $name );
400
- $sanitized[ $key ] = $value;
401
-
402
- }
403
-
404
- $pys_events[] = array(
405
- 'type' => pys_is_standard_event( $event ) ? 'track' : 'trackCustom',
406
- 'name' => $event,
407
- 'params' => $sanitized,
408
- 'delay' => $delay
409
- );
410
-
411
- }
412
-
413
- }
414
-
415
- if ( ! function_exists( 'pys_get_product_content_id' ) ) {
416
-
417
- /**
418
- * Return product id or sku.
419
- */
420
- function pys_get_product_content_id( $product_id ) {
421
-
422
- $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
423
-
424
- if ( pys_get_option( 'woo', 'content_id' ) == 'sku' ) {
425
- $content_id = get_post_meta( $product_id, '_sku', true );
426
- } else {
427
- $content_id = $product_id;
428
- }
429
-
430
- return apply_filters( 'pys_fb_pixel_woo_product_content_id', array( $content_id ), $product_id,
431
- $content_id_format );
432
-
433
- }
434
-
435
- }
436
-
437
- if ( ! function_exists( 'pys_get_woo_cart_item_product_id' ) ) {
438
-
439
- /**
440
- * Return main or variation product id.
441
- */
442
- function pys_get_woo_cart_item_product_id( $cart_item ) {
443
-
444
- $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
445
-
446
- if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
447
- $product_id = $cart_item['variation_id'];
448
- } else {
449
- $product_id = $cart_item['product_id'];
450
- }
451
-
452
- return apply_filters( 'pys_fb_pixel_woo_cart_item_product_id', $product_id, $cart_item, $content_id_format );
453
-
454
- }
455
-
456
- }
457
-
458
- if ( ! function_exists( 'pys_insert_attribute' ) ) {
459
-
460
- /**
461
- * Add attribute with value to a HTML tag.
462
- *
463
- * @param string $attr_name Attribute name, eg. "class"
464
- * @param string $attr_value Attribute value
465
- * @param string $content HTML content where attribute should be inserted
466
- * @param bool $overwrite Override existing value of attribute or append it
467
- * @param string $tag Selector name, eg. "button". Default "a"
468
- *
469
- * @return string Modified HTML content
470
- */
471
- function pys_insert_attribute( $attr_name, $attr_value, $content, $overwrite = false, $tag = 'a' ) {
472
-
473
- ## do not modify js attributes
474
- if( $attr_name == 'on' ) {
475
- return $content;
476
- }
477
-
478
- $attr_value = trim( $attr_value );
479
-
480
- try {
481
-
482
- $doc = new DOMDocument();
483
-
484
- /**
485
- * Old libxml does not support options parameter.
486
- *
487
- * @since 3.2.0
488
- */
489
- if ( defined( 'LIBXML_DOTTED_VERSION' ) && version_compare( LIBXML_DOTTED_VERSION, '2.6.0', '>=' ) &&
490
- version_compare( phpversion(), '5.4.0', '>=' )
491
- ) {
492
- @$doc->loadHTML( '<?xml encoding="UTF-8">' . $content, LIBXML_NOEMPTYTAG );
493
- } else {
494
- @$doc->loadHTML( '<?xml encoding="UTF-8">' . $content );
495
- }
496
-
497
- /**
498
- * Select top-level tag if it is not specified in args.
499
- *
500
- * @since: 5.0.6
501
- */
502
- if ( $tag == 'any' ) {
503
-
504
- /** @var DOMNodeList $node */
505
- $node = $doc->getElementsByTagName( 'body' );
506
-
507
- if ( $node->length == 0 ) {
508
- throw new Exception( 'Empty or wrong tag passed to filter.' );
509
- }
510
-
511
- $node = $node->item( 0 )->childNodes->item( 0 );
512
-
513
- } else {
514
- $node = $doc->getElementsByTagName( $tag )->item( 0 );
515
- }
516
-
517
- if ( is_null( $node ) ) {
518
- return $content;
519
- }
520
-
521
- /** @noinspection PhpUndefinedMethodInspection */
522
- $attribute = $node->getAttribute( $attr_name );
523
-
524
- // add attribute or override old one
525
- if ( empty( $attribute ) || $overwrite ) {
526
-
527
- /** @noinspection PhpUndefinedMethodInspection */
528
- $node->setAttribute( $attr_name, $attr_value );
529
-
530
- return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
531
-
532
- }
533
-
534
- // append value to exist attribute
535
- if ( $overwrite == false ) {
536
-
537
- $value = $attribute . ' ' . $attr_value;
538
- /** @noinspection PhpUndefinedMethodInspection */
539
- $node->setAttribute( $attr_name, $value );
540
-
541
- return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
542
-
543
- }
544
-
545
- } catch ( Exception $e ) {
546
-
547
- error_log( $e );
548
-
549
- }
550
-
551
- return $content;
552
-
553
- }
554
-
555
- }
556
-
557
- if ( ! function_exists( 'pys_is_disabled_for_role' ) ) {
558
-
559
- function pys_is_disabled_for_role() {
560
-
561
- $options = get_option( 'pixel_your_site' );
562
- $disabled_roles = $options['general'];
563
-
564
- $user = wp_get_current_user();
565
- foreach ( (array) $user->roles as $role ) {
566
-
567
- if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
568
-
569
- add_action( 'wp_head', 'pys_head_message', 1 );
570
- return true;
571
-
572
- }
573
-
574
- }
575
-
576
- if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
577
-
578
- add_action( 'wp_head', 'pys_head_message', 1 );
579
- return true;
580
-
581
- }
582
-
583
- return false;
584
-
585
- }
586
-
587
- }
588
-
589
- if( ! function_exists( 'pys_head_message' ) ) {
590
-
591
- /**
592
- * Output "disabled for role" and version number message to document head.
593
- */
594
- function pys_head_message() {
595
- echo "<!-- Facebook Pixel Code disabled for current role ( " . pys_get_version() . " ) -->\r\n";
596
- }
597
-
598
- }
599
-
600
- if( ! function_exists( 'pys_get_version' ) ) {
601
-
602
- function pys_get_version() {
603
-
604
- if( defined('PYS_PRO_VERSION') ) {
605
- $version = "PixelYourSite PRO v".PYS_PRO_VERSION;
606
- } elseif( defined('PYS_FREE_VERSION') ) {
607
- $version = "PixelYourSite FREE v".PYS_FREE_VERSION;
608
- } else {
609
- $version = null;
610
- }
611
-
612
- return $version;
613
-
614
- }
615
-
616
- }
617
-
618
- if( ! function_exists( 'pys_page_view_event' ) ) {
619
-
620
- /*
621
- * PageView event. Present on each page if pixel setup is enabled.
622
- */
623
- function pys_page_view_event() {
624
- pys_add_event( 'PageView' );
625
- }
626
-
627
- }
628
-
629
- if( ! function_exists( 'pys_general_event' ) ) {
630
-
631
- function pys_general_event() {
632
- global $post;
633
-
634
- if ( pys_get_option( 'general', 'general_event_enabled' ) == false ) {
635
- return;
636
- }
637
-
638
- $params = array();
639
- $event_name = pys_get_option( 'general', 'general_event_name' );
640
- $post_type = get_post_type();
641
- $delay = floatval( pys_get_option( 'general', 'general_event_delay', 0 ) );
642
-
643
- $on_posts_enabled = pys_get_option( 'general', 'general_event_on_posts_enabled' );
644
- $on_pages_enables = pys_get_option( 'general', 'general_event_on_pages_enabled' );
645
- $on_taxonomies_enabled = pys_get_option( 'general', 'general_event_on_tax_enabled' );
646
- $on_cpt_enabled = pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' );
647
- $on_woo_enabled = pys_get_option( 'general', 'general_event_on_woo_enabled' );
648
- $on_edd_enabled = pys_get_option( 'general', 'general_event_on_edd_enabled' );
649
- $track_tags_enabled = pys_get_option( 'general', 'general_event_add_tags', false );
650
-
651
- // Posts
652
- if ( $on_posts_enabled && is_singular( 'post' ) ) {
653
-
654
- $params['post_type'] = 'post';
655
- $params['content_name'] = $post->post_title;
656
- $params['post_id'] = $post->ID;
657
-
658
- if ( $terms = pys_get_content_taxonomies() ) {
659
- $params['content_category'] = $terms;
660
- }
661
-
662
- if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
663
- $params['tags'] = implode( ', ', $tags );
664
- }
665
-
666
- pys_add_event( $event_name, $params, $delay );
667
-
668
- return;
669
-
670
- }
671
-
672
- // Pages or Front Page
673
- if ( $on_pages_enables && ( is_singular( 'page' ) || is_home() ) ) {
674
-
675
- // exclude WooCommerce Cart page
676
- if ( pys_is_woocommerce_active() && is_cart() ) {
677
- return;
678
- }
679
-
680
- $params['post_type'] = 'page';
681
- $params['content_name'] = is_home() == true ? get_bloginfo( 'name' ) : $post->post_title;
682
-
683
- is_home() != true ? $params['post_id'] = $post->ID : null;
684
-
685
- pys_add_event( $event_name, $params, $delay );
686
-
687
- return;
688
-
689
- }
690
-
691
- // WooCommerce Shop page
692
- if ( $on_pages_enables && pys_is_woocommerce_active() && is_shop() ) {
693
-
694
- $page_id = wc_get_page_id( 'shop' );
695
-
696
- $params['post_type'] = 'page';
697
- $params['post_id'] = $page_id;
698
- $params['content_name'] = get_the_title( $page_id );;
699
-
700
- pys_add_event( $event_name, $params, $delay );
701
-
702
- return;
703
-
704
- }
705
-
706
- // Taxonomies (built-in and custom)
707
- if ( $on_taxonomies_enabled && ( is_category() || is_tax() || is_tag() ) ) {
708
-
709
- $term = null;
710
- $type = null;
711
-
712
- if ( is_category() ) {
713
-
714
- $cat = get_query_var( 'cat' );
715
- $term = get_category( $cat );
716
-
717
- $params['post_type'] = 'category';
718
- $params['content_name'] = $term->name;
719
- $params['post_id'] = $cat;
720
-
721
- } elseif ( is_tag() ) {
722
-
723
- $slug = get_query_var( 'tag' );
724
- $term = get_term_by( 'slug', $slug, 'post_tag' );
725
-
726
- $params['post_type'] = 'tag';
727
- $params['content_name'] = $term->name;
728
- $params['post_id'] = $term->term_id;
729
-
730
- } else {
731
-
732
- $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
733
-
734
- $params['post_type'] = get_query_var( 'taxonomy' );
735
- $params['content_name'] = $term->name;
736
- $params['post_id'] = $term->term_id;
737
-
738
- }
739
-
740
- pys_add_event( $event_name, $params, $delay );
741
-
742
- return;
743
-
744
- }
745
-
746
- // Custom Post Type
747
- if ( $on_cpt_enabled && $post_type != 'post' && $post_type != 'page' ) {
748
-
749
- // skip products and downloads is plugins are activated
750
- if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
751
- return;
752
- }
753
-
754
- $params['post_type'] = $post_type;
755
- $params['content_name'] = $post->post_title;
756
- $params['post_id'] = $post->ID;
757
-
758
- $taxonomies = get_post_taxonomies( get_post() );
759
- $terms = pys_get_content_taxonomies( $taxonomies[0] );
760
- if ( $terms ) {
761
- $params['content_category'] = $terms;
762
- }
763
-
764
- if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
765
- $params['tags'] = implode( ', ', $tags );
766
- }
767
-
768
- pys_add_event( $event_name, $params, $delay );
769
-
770
- return;
771
-
772
- }
773
-
774
- ## WooCommerce Products
775
- if ( $on_woo_enabled && pys_is_woocommerce_active() && $post_type == 'product' ) {
776
-
777
- pys_general_woo_event( $post, $track_tags_enabled, $delay, $event_name );
778
- return;
779
-
780
- }
781
-
782
- ## Easy Digital Downloads
783
- if ( $on_edd_enabled && pys_is_edd_active() && $post_type == 'download' ) {
784
-
785
- pys_general_edd_event( $post, $track_tags_enabled, $delay, $event_name );
786
- return;
787
-
788
- }
789
-
790
- }
791
-
792
- }
793
-
794
- if( ! function_exists( 'pys_search_event' ) ) {
795
-
796
- function pys_search_event() {
797
- global $posts;
798
-
799
- if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
800
- return;
801
- }
802
-
803
- $params = array(
804
- 'search_string' => $_REQUEST['s']
805
- );
806
-
807
- if ( pys_is_woocommerce_active() && pys_get_option( 'woo', 'enabled' )
808
- && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'product' ) {
809
-
810
- $content_ids = array();
811
- $limit = min( count( $posts ), 5 );
812
-
813
- for ( $i = 0; $i < $limit; $i ++ ) {
814
- $content_ids = array_merge( pys_get_product_content_id( $posts[ $i ]->ID ), $content_ids );
815
- }
816
-
817
- $params['content_ids'] = json_encode( $content_ids );
818
- $params['content_type'] = 'product';
819
-
820
- }
821
-
822
-
823
- pys_add_event( 'Search', $params );
824
-
825
- }
826
-
827
- }
828
-
829
- if( ! function_exists( 'pys_standard_events' ) ) {
830
-
831
- function pys_standard_events() {
832
- global $pys_custom_events;
833
-
834
- $std_events = get_option( 'pixel_your_site_std_events', array() );
835
-
836
- if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
837
- return;
838
- }
839
-
840
- foreach ( $std_events as $event ) {
841
-
842
- // skip wrong events
843
- if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
844
- continue;
845
- }
846
-
847
- // skip if current page does not match URL filter
848
- if ( pys_match_url( $event['pageurl'] ) == false ) {
849
- continue;
850
- }
851
-
852
- if ( $event['eventtype'] == 'CustomCode' ) {
853
-
854
- $custom_code = $event['code'];
855
- $custom_code = stripcslashes( $custom_code );
856
- $custom_code = trim( $custom_code );
857
-
858
- // add custom code to global custom events array
859
- $pys_custom_events[] = $custom_code;
860
-
861
- } else {
862
-
863
- $type = $event['eventtype'];
864
- $params = pys_clean_system_event_params( $event );
865
-
866
- pys_add_event( $type, $params );
867
-
868
- }
869
-
870
- }
871
-
872
- }
873
-
874
- }
875
-
876
- if( !function_exists( 'pys_pixel_init_event' ) ) {
877
-
878
- function pys_pixel_init_event() {
879
- global $pys_events;
880
-
881
- $pys_events[] = array(
882
- 'type' => 'init',
883
- 'name' => pys_get_option( 'general', 'pixel_id' ),
884
- 'params' => pys_pixel_init_params()
885
- );
886
-
887
- }
888
-
889
- }
890
-
891
- if( ! function_exists( 'pys_output_noscript_code' ) ) {
892
-
893
- function pys_output_noscript_code() {
894
- global $pys_events;
895
-
896
- if( empty( $pys_events ) ) {
897
- return;
898
- }
899
-
900
- foreach( $pys_events as $event ) {
901
-
902
- $args = array();
903
-
904
- if( $event['type'] == 'init' ) {
905
- continue;
906
- }
907
-
908
- $args['id'] = pys_get_option( 'general', 'pixel_id' );
909
- $args['ev'] = $event['name'];
910
- $args['noscript'] = 1;
911
-
912
- foreach ( $event['params'] as $param => $value ) {
913
- @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
914
- }
915
-
916
- $src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
917
-
918
- // note: ALT tag used to pass ADA compliance
919
- // @see: issue #63 for details
920
-
921
- echo "<noscript><img height='1' width='1' style='display: none;' src='{$src_attr}' alt='facebook_pixel'></noscript>";
922
-
923
- }
924
-
925
- }
926
-
927
- }
928
-
929
- if( ! function_exists( 'pys_output_js_events_code' ) ) {
930
-
931
- function pys_output_js_events_code() {
932
- global $pys_events;
933
-
934
- // allow external plugins modify events
935
- $pys_events = apply_filters( 'pys_prepared_events', $pys_events );
936
-
937
- if( empty( $pys_events ) ) {
938
- return;
939
- }
940
-
941
- wp_localize_script( 'pys-public', 'pys_events', $pys_events );
942
-
943
- }
944
-
945
- }
946
-
947
- if( ! function_exists( 'pys_output_custom_events_code' ) ) {
948
-
949
- function pys_output_custom_events_code() {
950
- global $pys_custom_events;
951
-
952
- if( empty( $pys_custom_events ) ) {
953
- return;
954
- }
955
-
956
- wp_localize_script( 'pys-public', 'pys_customEvents', $pys_custom_events );
957
-
958
- }
959
-
960
- }
961
-
962
- if( !function_exists( 'pys_clean_system_event_params' ) ) {
963
-
964
- function pys_clean_system_event_params( $params ) {
965
-
966
- // remove unused params
967
- unset( $params['pageurl'] );
968
- unset( $params['eventtype'] );
969
- unset( $params['code'] );
970
- unset( $params['trigger_type'] ); // pro
971
- unset( $params['custom_currency'] ); // pro
972
- unset( $params['url'] ); // pro
973
- unset( $params['css'] ); // pro
974
- unset( $params['custom_name'] ); // custom events
975
- unset( $params['scroll_pos'] ); // pro
976
- unset( $params['url_filter'] ); // pro - dynamic events
977
-
978
- return $params;
979
-
980
- }
981
-
982
- }
983
-
984
- if( !function_exists( 'pys_get_woo_checkout_params' ) ) {
985
-
986
- function pys_get_woo_checkout_params( $additional_params_enabled ) {
987
- global $woocommerce;
988
-
989
- // set defaults params
990
- $params = array();
991
- $params['content_type'] = 'product';
992
-
993
- $ids = array(); // cart items ids or sku
994
- $names = ''; // cart items names
995
- $categories = ''; // cart items categories
996
-
997
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
998
-
999
- $product_id = pys_get_woo_cart_item_product_id( $item );
1000
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
1001
-
1002
- // content_name, category_name for each cart item
1003
- if ( $additional_params_enabled ) {
1004
-
1005
- $temp = array();
1006
- pys_get_additional_woo_params( $product_id, $temp );
1007
-
1008
- $names .= isset( $temp['content_name'] ) ? $temp['content_name'] . ' ' : null;
1009
- $categories .= isset( $temp['category_name'] ) ? $temp['category_name'] . ' ' : null;
1010
-
1011
- }
1012
-
1013
- }
1014
-
1015
- if ( $additional_params_enabled ) {
1016
- $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
1017
- }
1018
-
1019
- $params['content_ids'] = json_encode( $ids );
1020
-
1021
- if ( ! empty( $names ) ) {
1022
- $params['content_name'] = $names;
1023
- }
1024
-
1025
- if ( ! empty( $categories ) ) {
1026
- $params['category_name'] = $categories;
1027
- }
1028
-
1029
- return $params;
1030
-
1031
- }
1032
-
1033
- }
1034
-
1035
- if( !function_exists( 'pys_get_default_options' ) ) {
1036
-
1037
- function pys_get_default_options() {
1038
-
1039
- $options = array();
1040
-
1041
- $options['general']['pixel_id'] = '';
1042
- $options['general']['enabled'] = 0;
1043
- $options['general']['add_traffic_source'] = 1;
1044
- $options['general']['enable_advance_matching'] = 1;
1045
- $options['general']['in_footer'] = 0;
1046
-
1047
- $options['general']['general_event_enabled'] = 1;
1048
- $options['general']['general_event_name'] = 'GeneralEvent';
1049
- $options['general']['general_event_on_posts_enabled'] = 1;
1050
- $options['general']['general_event_on_pages_enabled'] = 1;
1051
- $options['general']['general_event_on_tax_enabled'] = 1;
1052
- $options['general']['general_event_on_woo_enabled'] = 0;
1053
- $options['general']['general_event_on_edd_enabled'] = 0;
1054
- $options['general']['general_event_add_tags'] = 0;
1055
-
1056
- $options['general']['timeonpage_enabled'] = 1;
1057
-
1058
- $options['general']['search_event_enabled'] = 1;
1059
-
1060
- $options['std']['enabled'] = 0;
1061
-
1062
- $options['dyn']['enabled'] = 0;
1063
- $options['dyn']['enabled_on_content'] = 0;
1064
- $options['dyn']['enabled_on_widget'] = 0;
1065
-
1066
- $options['woo']['enabled'] = pys_is_woocommerce_active() ? 1 : 0;
1067
-
1068
- $options['woo']['content_id'] = 'id';
1069
- $options['woo']['variation_id'] = 'variation';
1070
-
1071
- $options['woo']['enable_additional_params'] = 1;
1072
- $options['woo']['enable_tags'] = 1;
1073
- $options['woo']['tax'] = 'incl';
1074
-
1075
- $options['woo']['on_view_content'] = 1;
1076
- $options['woo']['enable_view_content_value'] = 1;
1077
- $options['woo']['view_content_value_option'] = 'price';
1078
- $options['woo']['view_content_percent_value'] = '';
1079
- $options['woo']['view_content_global_value'] = '';
1080
-
1081
- $options['woo']['on_view_category'] = 1;
1082
-
1083
- $options['woo']['on_add_to_cart_btn'] = 1;
1084
- $options['woo']['on_add_to_cart_page'] = 0;
1085
- $options['woo']['on_add_to_cart_checkout'] = 0;
1086
- $options['woo']['enable_add_to_cart_value'] = 1;
1087
- $options['woo']['add_to_cart_value_option'] = 'price';
1088
- $options['woo']['add_to_cart_percent_value'] = '';
1089
- $options['woo']['add_to_cart_global_value'] = '';
1090
-
1091
- $options['woo']['on_checkout_page'] = 1;
1092
- $options['woo']['enable_checkout_value'] = 1;
1093
- $options['woo']['checkout_value_option'] = 'price';
1094
- $options['woo']['checkout_percent_value'] = '';
1095
- $options['woo']['checkout_global_value'] = '';
1096
-
1097
- $options['woo']['on_thank_you_page'] = 1;
1098
- $options['woo']['enable_purchase_value'] = 1;
1099
- $options['woo']['purchase_fire_once'] = 1;
1100
- $options['woo']['purchase_transport'] = 'included';
1101
- $options['woo']['purchase_value_option'] = 'total';
1102
- $options['woo']['purchase_percent_value'] = '';
1103
- $options['woo']['purchase_global_value'] = '';
1104
-
1105
- $options['woo']['purchase_add_address'] = 1;
1106
- $options['woo']['purchase_add_payment_method'] = 1;
1107
- $options['woo']['purchase_add_shipping_method'] = 1;
1108
- $options['woo']['purchase_add_coupons'] = 1;
1109
-
1110
- $options['woo']['enable_aff_event'] = 0;
1111
- $options['woo']['aff_event'] = 'predefined';
1112
- $options['woo']['aff_predefined_value'] = 'Lead';
1113
- $options['woo']['aff_custom_value'] = '';
1114
- $options['woo']['aff_value_option'] = 'none';
1115
- $options['woo']['aff_global_value'] = '';
1116
-
1117
- $options['woo']['enable_paypal_event'] = 0;
1118
- $options['woo']['pp_event'] = 'predefined';
1119
- $options['woo']['pp_predefined_value'] = 'InitiatePayment';
1120
- $options['woo']['pp_custom_value'] = '';
1121
- $options['woo']['pp_value_option'] = 'none';
1122
- $options['woo']['pp_global_value'] = '';
1123
-
1124
- /**
1125
- * Easy Digital Downloads
1126
- */
1127
-
1128
- $options['edd']['enabled'] = pys_is_edd_active() ? 1 : 0;
1129
-
1130
- $options['edd']['content_id'] = 'id';
1131
- $options['edd']['enable_additional_params'] = 1;
1132
- $options['edd']['enable_tags'] = 1;
1133
- $options['edd']['tax'] = 'incl';
1134
-
1135
- $options['edd']['on_view_content'] = 1;
1136
- $options['edd']['on_view_content_delay'] = null;
1137
- $options['edd']['enable_view_content_value'] = 1;
1138
- $options['edd']['view_content_value_option'] = 'price';
1139
- $options['edd']['view_content_percent_value'] = null;
1140
- $options['edd']['view_content_global_value'] = null;
1141
-
1142
- $options['edd']['on_view_category'] = 1;
1143
-
1144
- $options['edd']['on_add_to_cart_btn'] = 1;
1145
- $options['edd']['on_add_to_cart_checkout'] = 0;
1146
- $options['edd']['enable_add_to_cart_value'] = 1;
1147
- $options['edd']['add_to_cart_value_option'] = 'price';
1148
- $options['edd']['add_to_cart_percent_value'] = null;
1149
- $options['edd']['add_to_cart_global_value'] = null;
1150
-
1151
- $options['edd']['on_checkout_page'] = 1;
1152
- $options['edd']['enable_checkout_value'] = 1;
1153
- $options['edd']['checkout_value_option'] = 'price';
1154
- $options['edd']['checkout_percent_value'] = null;
1155
- $options['edd']['checkout_global_value'] = null;
1156
-
1157
- $options['edd']['on_success_page'] = 1;
1158
- $options['edd']['enable_purchase_value'] = 1;
1159
- $options['edd']['purchase_fire_once'] = 1;
1160
- $options['edd']['purchase_value_option'] = 'total';
1161
- $options['edd']['purchase_percent_value'] = null;
1162
- $options['edd']['purchase_global_value'] = null;
1163
-
1164
- $options['edd']['purchase_add_address'] = true;
1165
- $options['edd']['purchase_add_payment_method'] = true;
1166
- $options['edd']['purchase_add_coupons'] = true;
1167
-
1168
- return apply_filters( 'pys_fb_pixel_setting_defaults', $options );
1169
-
1170
- }
1171
-
1172
- }
1173
-
1174
- if( ! function_exists( 'pys_get_custom_params' ) ) {
1175
-
1176
- /**
1177
- * Extract non-system params array
1178
- */
1179
- function pys_get_custom_params( $event ) {
1180
-
1181
- if( !is_array( $event ) || empty( $event ) ) {
1182
- return array();
1183
- }
1184
-
1185
- $system_params = array(
1186
- 'trigger_type',
1187
- 'url_filter',
1188
- 'url',
1189
- 'css',
1190
- 'pageurl',
1191
- 'eventtype',
1192
- 'value',
1193
- 'currency',
1194
- 'custom_currency',
1195
- 'content_name',
1196
- 'content_ids',
1197
- 'content_type',
1198
- 'content_category',
1199
- 'num_items',
1200
- 'order_id',
1201
- 'search_string',
1202
- 'status',
1203
- 'code',
1204
- 'custom_name',
1205
- 'scroll_pos'
1206
- );
1207
-
1208
- $custom_params = array();
1209
- foreach( $event as $param => $value ) {
1210
-
1211
- // skip standard params
1212
- if( in_array( $param, $system_params ) ) {
1213
- continue;
1214
- }
1215
-
1216
- $custom_params[ $param ] = $value;
1217
-
1218
- }
1219
-
1220
-
1221
- return $custom_params;
1222
-
1223
- }
1224
-
1225
- }
1226
-
1227
- if( ! function_exists( 'pys_is_standard_event' ) ) {
1228
-
1229
- function pys_is_standard_event( $eventtype ) {
1230
-
1231
- $std_events = array(
1232
- 'PageView',
1233
- 'ViewContent',
1234
- 'Search',
1235
- 'AddToCart',
1236
- 'AddToWishlist',
1237
- 'InitiateCheckout',
1238
- 'AddPaymentInfo',
1239
- 'Purchase',
1240
- 'Lead'
1241
- );
1242
-
1243
- return in_array( $eventtype, $std_events );
1244
-
1245
- }
1246
-
1247
- }
1248
-
1249
- if( ! function_exists( 'pys_pixel_init_params' ) ) {
1250
-
1251
- /**
1252
- * Add extra params to FB init call.
1253
- */
1254
- function pys_pixel_init_params() {
1255
-
1256
- $params = array();
1257
- $params = apply_filters( 'pys_pixel_init_params', $params );
1258
-
1259
- $sanitized = array();
1260
-
1261
- // sanitize params
1262
- foreach ( $params as $name => $value ) {
1263
-
1264
- if ( empty( $value ) ) {
1265
- continue;
1266
- }
1267
-
1268
- $key = esc_js( $name );
1269
- $sanitized[ $key ] = $value;
1270
-
1271
- }
1272
-
1273
- return $sanitized;
1274
-
1275
- }
1276
-
1277
- }
1278
-
1279
- if( ! function_exists( 'pys_woocommerce_events' ) ) {
1280
-
1281
- function pys_woocommerce_events() {
1282
-
1283
- if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
1284
- return;
1285
- }
1286
-
1287
- pys_get_woo_code();
1288
-
1289
- // WooCommerce non-ajax AddToCart Event handler
1290
- if ( pys_get_option( 'woo', 'on_add_to_cart_btn' ) && isset( $_REQUEST['add-to-cart'] ) ) {
1291
-
1292
- if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $_REQUEST['variation_id'] ) ) {
1293
- $product_id = $_REQUEST['variation_id'];
1294
- } else {
1295
- $product_id = isset( $_REQUEST['add-to-cart'] ) ? (int) $_REQUEST['add-to-cart'] : null;
1296
- }
1297
-
1298
- $qty = isset( $_REQUEST['quantity'] ) ? (int) $_REQUEST['quantity'] : 1;
1299
- $params = pys_get_woo_product_addtocart_params( $product_id, $qty );
1300
-
1301
- pys_add_event( 'AddToCart', $params );
1302
-
1303
- }
1304
-
1305
- }
1306
-
1307
- }
1308
-
1309
- if( ! function_exists( 'pys_output_options' ) ) {
1310
-
1311
- function pys_output_options() {
1312
-
1313
- $options = array(
1314
- 'site_url' => get_site_url(),
1315
- 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1316
- );
1317
-
1318
- wp_localize_script( 'pys-public', 'pys_options', $options );
1319
-
1320
- }
1321
-
1322
- }
1323
-
1324
- if( ! function_exists( 'pys_head_comments' ) ) {
1325
-
1326
- function pys_head_comments() {
1327
-
1328
- if( defined( 'PYS_PRO_VERSION' ) ) {
1329
- $version = "PRO v" . PYS_PRO_VERSION;
1330
- } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1331
- $version = "FREE v" . PYS_FREE_VERSION;
1332
- } else {
1333
- $version = null;
1334
- }
1335
-
1336
- ?>
1337
-
1338
- <!-- Facebook Pixel code is added on this page by PixelYourSite <?php echo esc_attr( $version ); ?> plugin. You can test it with Pixel Helper Chrome Extension. -->
1339
-
1340
- <?php
1341
- }
1342
-
1343
- }
1344
-
1345
- if( ! function_exists( 'pys_render_event_code' ) ) {
1346
-
1347
- /**
1348
- * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1349
- */
1350
- function pys_render_event_code( $event_name, $params ) {
1351
-
1352
- $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1353
-
1354
- $params = pys_clean_system_event_params( $params );
1355
-
1356
- $event_params = '';
1357
- foreach( $params as $name => $value ) {
1358
-
1359
- if( empty( $value ) && $value !== "0" ) {
1360
- continue;
1361
- }
1362
-
1363
- $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1364
-
1365
- }
1366
-
1367
- $event_params = ltrim( $event_params );
1368
- $event_params = rtrim( $event_params, "," );
1369
-
1370
- return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1371
-
1372
- }
1373
-
1374
- }
1375
-
1376
- if( !function_exists( 'pys_add_domain_param' ) ) {
1377
-
1378
- function pys_add_domain_param( $params, $event ) {
1379
-
1380
- // get home URL without protocol
1381
- $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1382
- return $params;
1383
-
1384
- }
1385
-
1386
- }
1387
-
1388
- if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
1389
-
1390
- function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
1391
-
1392
- // get WP_Post object
1393
- if ( is_numeric( $post ) ) {
1394
- $id = absint( $post );
1395
- $_post = get_post( $id );
1396
- } elseif ( $post instanceof WC_Product ) {
1397
- $_post = $post->post;
1398
- } elseif ( isset( $post->ID ) ) {
1399
- $_post = $post;
1400
- } else {
1401
- return;
1402
- }
1403
-
1404
- $params['content_name'] = $_post->post_title;
1405
-
1406
- $terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
1407
- if ( $terms ) {
1408
- $params['category_name'] = $terms;
1409
- }
1410
-
1411
- }
1412
-
1413
- }
1414
-
1415
- if ( ! function_exists( 'pys_get_object_tags' ) ) {
1416
-
1417
- /**
1418
- * @param int|WP_Post $post Post ID or object
1419
- * @param string $taxonomy Taxonomy name
1420
- *
1421
- * @return array Array of terms titles on success or empty array
1422
- */
1423
- function pys_get_object_tags( $post, $taxonomy ) {
1424
-
1425
- $tags = array();
1426
- $terms = get_the_terms( $post, $taxonomy );
1427
-
1428
- if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1429
-
1430
- foreach ( $terms as $term ) {
1431
- $tags[] = html_entity_decode( $term->name );
1432
- }
1433
-
1434
- }
1435
-
1436
- return $tags;
1437
-
1438
- }
1439
-
1440
- }
1441
-
1442
- if ( ! function_exists( 'pys_delete_events' ) ) {
1443
-
1444
- function pys_delete_events( $events_ids, $events_type ) {
1445
-
1446
- if ( $events_type == 'standard' ) {
1447
- $option_name = 'pixel_your_site_std_events';
1448
- } else {
1449
- $option_name = 'pixel_your_site_dyn_events';
1450
- }
1451
-
1452
- $events = (array) get_option( $option_name );
1453
-
1454
- if ( empty( $events ) ) {
1455
- return;
1456
- }
1457
-
1458
- foreach ( $events_ids as $id ) {
1459
- unset( $events[ $id ] );
1460
- }
1461
-
1462
- update_option( $option_name, $events );
1463
-
1464
- }
1465
-
1466
- }
1467
-
1468
- if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
1469
-
1470
- function pys_is_wc_version_gte( $version ) {
1471
-
1472
- if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
1473
- return version_compare( WC_VERSION, $version, '>=' );
1474
- } else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
1475
- return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
1476
- } else {
1477
- return false;
1478
- }
1479
-
1480
- }
1481
-
1482
  }
1
+ <?php
2
+ /**
3
+ * Common functions for both versions.
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit; // Exit if accessed directly.
8
+ }
9
+
10
+ /**
11
+ * Check if WooCommerce plugin is installed and activated.
12
+ */
13
+ if( !function_exists( 'pys_is_woocommerce_active' ) ) {
14
+
15
+ function pys_is_woocommerce_active() {
16
+ return class_exists( 'WooCommerce' ) == true ? true : false;
17
+ }
18
+
19
+ }
20
+
21
+ /**
22
+ * Check if Easy Digital Downloads plugin is installed and activated.
23
+ */
24
+ if( !function_exists( 'pys_is_edd_active' ) ) {
25
+
26
+ function pys_is_edd_active() {
27
+ return class_exists( 'Easy_Digital_Downloads' ) == true ? true : false;
28
+ }
29
+
30
+ }
31
+
32
+ if ( ! function_exists( 'pys_is_pcf_pro_active' ) ) {
33
+
34
+ function pys_is_pcf_pro_active() {
35
+ return class_exists( 'wpwoof_product_catalog' ) == true ? true : false;
36
+ }
37
+
38
+ }
39
+
40
+ if( !function_exists( 'pys_get_option' ) ) {
41
+
42
+ /**
43
+ * Return option value.
44
+ *
45
+ * @param string $section Options section, eg. 'general', 'woo', etc.
46
+ * @param string $option Option name
47
+ * @param mixed|string $default Default option value
48
+ *
49
+ * @return mixed Option or default option value
50
+ */
51
+ function pys_get_option( $section, $option, $default = '' ) {
52
+
53
+ $options = get_option( 'pixel_your_site' );
54
+
55
+ return isset( $options[ $section ][ $option ] ) ? $options[ $section ][ $option ] : $default;
56
+
57
+ }
58
+
59
+ }
60
+
61
+ if( !function_exists( 'pys_checkbox_state' ) ) {
62
+
63
+ /**
64
+ * @param string $section Option section name
65
+ * @param string $option Option name
66
+ * @param bool $echo Echo or return value
67
+ * @param int $checked Value to state compare
68
+ *
69
+ * @return string
70
+ */
71
+ function pys_checkbox_state( $section, $option, $echo = true, $checked = 1 ) {
72
+
73
+ $options = get_option( 'pixel_your_site' );
74
+
75
+ if ( isset( $options[ $section ][ $option ] ) ) {
76
+ $value = $options[ $section ][ $option ] == $checked ? 'checked' : '';
77
+ } else {
78
+ $value = '';
79
+ }
80
+
81
+ if( $echo ) {
82
+ echo $value;
83
+ }
84
+
85
+ return $value;
86
+
87
+ }
88
+
89
+ }
90
+
91
+ if ( ! function_exists( 'pys_checkbox' ) ) {
92
+
93
+ /**
94
+ * Echos checkbox input.
95
+ *
96
+ * @param string $section Input section name
97
+ * @param string $option Input option name
98
+ * @param string $classes Class names (optional)
99
+ * @param int $value Input value (optional)
100
+ */
101
+ function pys_checkbox( $section, $option, $classes = '', $value = 1 ) {
102
+
103
+ $state = pys_checkbox_state( $section, $option, false, $value );
104
+ $value = esc_attr( $value );
105
+
106
+ echo "<input type='checkbox' value='$value' name='pys[$section][$option]' class='$classes' $state>";
107
+
108
+ }
109
+
110
+ }
111
+
112
+ if ( ! function_exists( 'pys_text_field' ) ) {
113
+
114
+ /**
115
+ * Echos text input.
116
+ *
117
+ * @param string $section Input section name
118
+ * @param string $option Input option name
119
+ */
120
+ function pys_text_field( $section, $option ) {
121
+
122
+ $value = pys_get_option( $section, $option );
123
+ $value = esc_attr( $value );
124
+
125
+ echo "<input type='text' value='$value' name='pys[$section][$option]'>";
126
+
127
+ }
128
+
129
+ }
130
+
131
+ if ( ! function_exists( 'pys_radio_box' ) ) {
132
+
133
+ /**
134
+ * Echos radio box input.
135
+ *
136
+ * @param string $section Input section name
137
+ * @param string $option Input option name
138
+ * @param string $value Option value
139
+ */
140
+ function pys_radio_box( $section, $option, $value ) {
141
+
142
+ $state = pys_radio_state( $section, $option, $value );
143
+ echo "<input type='radio' value='$value' name='pys[$section][$option]' $state>";
144
+
145
+ }
146
+
147
+ }
148
+
149
+ /**
150
+ * Return radio box state.
151
+ */
152
+ if( !function_exists( 'pys_radio_state' ) ) {
153
+
154
+ function pys_radio_state( $section, $option, $value ) {
155
+
156
+ $options = get_option( 'pixel_your_site' );
157
+
158
+ if ( isset( $options[ $section ][ $option ] ) ) {
159
+
160
+ return $options[ $section ][ $option ] == $value ? 'checked' : '';
161
+
162
+ } else {
163
+
164
+ $defaults = pys_get_default_options();
165
+ return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
166
+
167
+ }
168
+
169
+ }
170
+
171
+ }
172
+
173
+ /**
174
+ * Facebook Pixel Event types options html.
175
+ */
176
+ if( !function_exists( 'pys_event_types_select_options' ) ) {
177
+
178
+ function pys_event_types_select_options( $current = null, $full = true ) {
179
+ ?>
180
+
181
+ <option <?php selected( null, $current ); ?> disabled>Select Type</option>
182
+ <option <?php selected( 'ViewContent', $current ); ?> value="ViewContent">ViewContent</option>
183
+
184
+ <?php if ( $full ) : ?>
185
+
186
+ <option <?php selected( 'Search', $current ); ?> value="Search">Search</option>
187
+
188
+ <?php endif; ?>
189
+
190
+ <option <?php selected( 'AddToCart', $current ); ?> value="AddToCart">AddToCart</option>
191
+ <option <?php selected( 'AddToWishlist', $current ); ?> value="AddToWishlist">AddToWishlist</option>
192
+ <option <?php selected( 'InitiateCheckout', $current ); ?> value="InitiateCheckout">InitiateCheckout</option>
193
+ <option <?php selected( 'AddPaymentInfo', $current ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
194
+ <option <?php selected( 'Purchase', $current ); ?> value="Purchase">Purchase</option>
195
+ <option <?php selected( 'Lead', $current ); ?> value="Lead">Lead</option>
196
+ <option <?php selected( 'CompleteRegistration', $current ); ?> value="CompleteRegistration">CompleteRegistration</option>
197
+
198
+ <?php if ( $full ) : ?>
199
+
200
+ <option disabled></option>
201
+ <option <?php selected( 'CustomEvent', $current ); ?> value="CustomEvent">Custom event</option>
202
+ <option <?php selected( 'CustomCode', $current); ?> value="CustomCode">Custom event code</option>
203
+
204
+ <?php endif; ?>
205
+
206
+ <?php
207
+ }
208
+
209
+ }
210
+
211
+ /**
212
+ * Current Page Full URL without trailing slash
213
+ */
214
+ if( !function_exists( 'pys_get_current_url' ) ) {
215
+
216
+ function pys_get_current_url() {
217
+
218
+ $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
219
+ $current_url = rtrim( $current_url, '/' );
220
+
221
+ return $current_url;
222
+
223
+ }
224
+
225
+ }
226
+
227
+ /**
228
+ * Returns relative path without protocol, host, slashes.
229
+ */
230
+ if( !function_exists( 'pys_get_relative_path' ) ) {
231
+
232
+ function pys_get_relative_path( $url ) {
233
+
234
+ $host = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', home_url() );
235
+
236
+ $url = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', $url );
237
+ $url = str_replace( $host, '', $url );
238
+
239
+ $url = trim( $url );
240
+ $url = ltrim( $url, '/' );
241
+ $url = rtrim( $url, '/' );
242
+
243
+ return $url;
244
+
245
+ }
246
+
247
+ }
248
+
249
+ /**
250
+ * Check if needle URL (full or relative) matches with current.
251
+ */
252
+ if( !function_exists( 'pys_match_url' ) ) {
253
+
254
+ function pys_match_url( $match_url, $current_url = '' ) {
255
+
256
+ // use current url by default
257
+ if ( ! isset( $current_url ) || empty( $current_url ) ) {
258
+ $current_url = pys_get_current_url();
259
+ }
260
+
261
+ $current_url = pys_get_relative_path( $current_url );
262
+ $match_url = pys_get_relative_path( $match_url );
263
+
264
+ if ( substr( $match_url, - 1 ) == '*' ) {
265
+ // if match_url ends with wildcard
266
+
267
+ $match_url = rtrim( $match_url, '*' );
268
+
269
+ if ( pys_startsWith( $current_url, $match_url ) ) {
270
+ return true;
271
+ }
272
+
273
+ } else {
274
+ // exact url
275
+
276
+ if ( $current_url == $match_url ) {
277
+ return true;
278
+ }
279
+
280
+ }
281
+
282
+ return false;
283
+
284
+ }
285
+
286
+ }
287
+
288
+ if( !function_exists( 'pys_startsWith' ) ) {
289
+
290
+ function pys_startsWith( $haystack, $needle ) {
291
+ // search backwards starting from haystack length characters from the end
292
+ return $needle === "" || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
293
+ }
294
+
295
+ }
296
+
297
+ if( !function_exists( 'pys_endsWith' ) ) {
298
+
299
+ function pys_endsWith( $haystack, $needle ) {
300
+ // search forward starting from end minus needle length characters
301
+ return $needle === "" || ( ( $temp = strlen( $haystack ) - strlen( $needle ) ) >= 0 && strpos( $haystack, $needle, $temp ) !== false );
302
+ }
303
+
304
+ }
305
+
306
+ if( !function_exists( 'pys_currency_options' ) ) {
307
+
308
+ function pys_currency_options( $current = 'USD' ) {
309
+
310
+ $currencies = apply_filters( 'pys_currencies_list', array(
311
+ 'AUD' => 'Australian Dollar',
312
+ 'BRL' => 'Brazilian Real',
313
+ 'CAD' => 'Canadian Dollar',
314
+ 'CZK' => 'Czech Koruna',
315
+ 'DKK' => 'Danish Krone',
316
+ 'EUR' => 'Euro',
317
+ 'HKD' => 'Hong Kong Dollar',
318
+ 'HUF' => 'Hungarian Forint',
319
+ 'IDR' => 'Indonesian Rupiah',
320
+ 'ILS' => 'Israeli New Sheqel',
321
+ 'JPY' => 'Japanese Yen',
322
+ 'KRW' => 'Korean Won',
323
+ 'MYR' => 'Malaysian Ringgit',
324
+ 'MXN' => 'Mexican Peso',
325
+ 'NOK' => 'Norwegian Krone',
326
+ 'NZD' => 'New Zealand Dollar',
327
+ 'PHP' => 'Philippine Peso',
328
+ 'PLN' => 'Polish Zloty',
329
+ 'RON' => 'Romanian Leu',
330
+ 'GBP' => 'Pound Sterling',
331
+ 'SGD' => 'Singapore Dollar',
332
+ 'SEK' => 'Swedish Krona',
333
+ 'CHF' => 'Swiss Franc',
334
+ 'TWD' => 'Taiwan New Dollar',
335
+ 'THB' => 'Thai Baht',
336
+ 'TRY' => 'Turkish Lira',
337
+ 'USD' => 'U.S. Dollar',
338
+ 'ZAR' => 'South African Rands'
339
+ ) );
340
+
341
+ foreach( $currencies as $symbol => $name ) {
342
+ echo '<option ' . selected( $symbol, $current, false ) . ' value="' . esc_attr( $symbol ) . '">' . esc_html( $name ) . '</option>';
343
+ }
344
+
345
+ }
346
+
347
+ }
348
+
349
+ /**
350
+ * Extract Object taxonomies list.
351
+ */
352
+ if( !function_exists( 'pys_get_content_taxonomies' ) ) {
353
+
354
+ function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
355
+
356
+ $post_id = isset( $post_id ) ? $post_id : get_the_ID();
357
+ $terms = get_the_terms( $post_id, $taxonomy );
358
+
359
+ if ( is_wp_error( $terms ) || empty ( $terms ) ) {
360
+ return false;
361
+ }
362
+
363
+ $list = array();
364
+
365
+ foreach( $terms as $term ) {
366
+ $list[ $term->term_id ] = html_entity_decode( $term->name );
367
+ }
368
+
369
+ return implode( ', ', $list );
370
+
371
+ }
372
+
373
+ }
374
+
375
+ if( !function_exists( 'pys_add_event' ) ) {
376
+
377
+ /**
378
+ * Add event with params to global events list.
379
+ *
380
+ * @param string $event Event name, eg. "PageView"
381
+ * @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
382
+ * @param int $delay Optional. If set, event will be fired with desired delay in seconds.
383
+ */
384
+ function pys_add_event( $event, $params = array(), $delay = 0 ) {
385
+ global $pys_events;
386
+
387
+ $params = apply_filters( 'pys_event_params', $params, $event );
388
+
389
+ $sanitized = array();
390
+
391
+ // sanitize param names and its values
392
+ foreach ( $params as $name => $value ) {
393
+
394
+ // skip empty but not zero values
395
+ if ( empty( $value ) && ! is_numeric( $value ) ) {
396
+ continue;
397
+ }
398
+
399
+ $key = esc_js( $name );
400
+ $sanitized[ $key ] = $value;
401
+
402
+ }
403
+
404
+ $pys_events[] = array(
405
+ 'type' => pys_is_standard_event( $event ) ? 'track' : 'trackCustom',
406
+ 'name' => $event,
407
+ 'params' => $sanitized,
408
+ 'delay' => $delay
409
+ );
410
+
411
+ }
412
+
413
+ }
414
+
415
+ if ( ! function_exists( 'pys_get_product_content_id' ) ) {
416
+
417
+ /**
418
+ * Return product id or sku.
419
+ */
420
+ function pys_get_product_content_id( $product_id ) {
421
+
422
+ $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
423
+
424
+ if ( pys_get_option( 'woo', 'content_id' ) == 'sku' ) {
425
+ $content_id = get_post_meta( $product_id, '_sku', true );
426
+ } else {
427
+ $content_id = $product_id;
428
+ }
429
+
430
+ return apply_filters( 'pys_fb_pixel_woo_product_content_id', array( $content_id ), $product_id,
431
+ $content_id_format );
432
+
433
+ }
434
+
435
+ }
436
+
437
+ if ( ! function_exists( 'pys_get_woo_cart_item_product_id' ) ) {
438
+
439
+ /**
440
+ * Return main or variation product id.
441
+ */
442
+ function pys_get_woo_cart_item_product_id( $cart_item ) {
443
+
444
+ $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
445
+
446
+ if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
447
+ $product_id = $cart_item['variation_id'];
448
+ } else {
449
+ $product_id = $cart_item['product_id'];
450
+ }
451
+
452
+ return apply_filters( 'pys_fb_pixel_woo_cart_item_product_id', $product_id, $cart_item, $content_id_format );
453
+
454
+ }
455
+
456
+ }
457
+
458
+ if ( ! function_exists( 'pys_is_disabled_for_role' ) ) {
459
+
460
+ function pys_is_disabled_for_role() {
461
+
462
+ $options = get_option( 'pixel_your_site' );
463
+ $disabled_roles = $options['general'];
464
+
465
+ $user = wp_get_current_user();
466
+ foreach ( (array) $user->roles as $role ) {
467
+
468
+ if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
469
+
470
+ add_action( 'wp_head', 'pys_head_message', 1 );
471
+ return true;
472
+
473
+ }
474
+
475
+ }
476
+
477
+ if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
478
+
479
+ add_action( 'wp_head', 'pys_head_message', 1 );
480
+ return true;
481
+
482
+ }
483
+
484
+ return false;
485
+
486
+ }
487
+
488
+ }
489
+
490
+ if( ! function_exists( 'pys_head_message' ) ) {
491
+
492
+ /**
493
+ * Output "disabled for role" and version number message to document head.
494
+ */
495
+ function pys_head_message() {
496
+ echo "<!-- Facebook Pixel Code disabled for current role ( " . pys_get_version() . " ) -->\r\n";
497
+ }
498
+
499
+ }
500
+
501
+ if( ! function_exists( 'pys_get_version' ) ) {
502
+
503
+ function pys_get_version() {
504
+
505
+ if( defined('PYS_PRO_VERSION') ) {
506
+ $version = "PixelYourSite PRO v".PYS_PRO_VERSION;
507
+ } elseif( defined('PYS_FREE_VERSION') ) {
508
+ $version = "PixelYourSite FREE v".PYS_FREE_VERSION;
509
+ } else {
510
+ $version = null;
511
+ }
512
+
513
+ return $version;
514
+
515
+ }
516
+
517
+ }
518
+
519
+ if( ! function_exists( 'pys_page_view_event' ) ) {
520
+
521
+ /*
522
+ * PageView event. Present on each page if pixel setup is enabled.
523
+ */
524
+ function pys_page_view_event() {
525
+ pys_add_event( 'PageView' );
526
+ }
527
+
528
+ }
529
+
530
+ if( ! function_exists( 'pys_general_event' ) ) {
531
+
532
+ function pys_general_event() {
533
+ global $post;
534
+
535
+ if ( pys_get_option( 'general', 'general_event_enabled' ) == false ) {
536
+ return;
537
+ }
538
+
539
+ $params = array();
540
+ $event_name = pys_get_option( 'general', 'general_event_name' );
541
+ $post_type = get_post_type();
542
+ $delay = floatval( pys_get_option( 'general', 'general_event_delay', 0 ) );
543
+
544
+ $on_posts_enabled = pys_get_option( 'general', 'general_event_on_posts_enabled' );
545
+ $on_pages_enables = pys_get_option( 'general', 'general_event_on_pages_enabled' );
546
+ $on_taxonomies_enabled = pys_get_option( 'general', 'general_event_on_tax_enabled' );
547
+ $on_cpt_enabled = pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' );
548
+ $on_woo_enabled = pys_get_option( 'general', 'general_event_on_woo_enabled' );
549
+ $on_edd_enabled = pys_get_option( 'general', 'general_event_on_edd_enabled' );
550
+ $track_tags_enabled = pys_get_option( 'general', 'general_event_add_tags', false );
551
+
552
+ // Posts
553
+ if ( $on_posts_enabled && is_singular( 'post' ) ) {
554
+
555
+ $params['post_type'] = 'post';
556
+ $params['content_name'] = $post->post_title;
557
+ $params['post_id'] = $post->ID;
558
+
559
+ if ( $terms = pys_get_content_taxonomies() ) {
560
+ $params['content_category'] = $terms;
561
+ }
562
+
563
+ if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
564
+ $params['tags'] = implode( ', ', $tags );
565
+ }
566
+
567
+ pys_add_event( $event_name, $params, $delay );
568
+
569
+ return;
570
+
571
+ }
572
+
573
+ // Pages or Front Page
574
+ if ( $on_pages_enables && ( is_singular( 'page' ) || is_home() ) ) {
575
+
576
+ // exclude WooCommerce Cart page
577
+ if ( pys_is_woocommerce_active() && is_cart() ) {
578
+ return;
579
+ }
580
+
581
+ $params['post_type'] = 'page';
582
+ $params['content_name'] = is_home() == true ? get_bloginfo( 'name' ) : $post->post_title;
583
+
584
+ is_home() != true ? $params['post_id'] = $post->ID : null;
585
+
586
+ pys_add_event( $event_name, $params, $delay );
587
+
588
+ return;
589
+
590
+ }
591
+
592
+ // WooCommerce Shop page
593
+ if ( $on_pages_enables && pys_is_woocommerce_active() && is_shop() ) {
594
+
595
+ $page_id = wc_get_page_id( 'shop' );
596
+
597
+ $params['post_type'] = 'page';
598
+ $params['post_id'] = $page_id;
599
+ $params['content_name'] = get_the_title( $page_id );;
600
+
601
+ pys_add_event( $event_name, $params, $delay );
602
+
603
+ return;
604
+
605
+ }
606
+
607
+ // Taxonomies (built-in and custom)
608
+ if ( $on_taxonomies_enabled && ( is_category() || is_tax() || is_tag() ) ) {
609
+
610
+ $term = null;
611
+ $type = null;
612
+
613
+ if ( is_category() ) {
614
+
615
+ $cat = get_query_var( 'cat' );
616
+ $term = get_category( $cat );
617
+
618
+ $params['post_type'] = 'category';
619
+ $params['content_name'] = $term->name;
620
+ $params['post_id'] = $cat;
621
+
622
+ } elseif ( is_tag() ) {
623
+
624
+ $slug = get_query_var( 'tag' );
625
+ $term = get_term_by( 'slug', $slug, 'post_tag' );
626
+
627
+ $params['post_type'] = 'tag';
628
+ $params['content_name'] = $term->name;
629
+ $params['post_id'] = $term->term_id;
630
+
631
+ } else {
632
+
633
+ $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
634
+
635
+ $params['post_type'] = get_query_var( 'taxonomy' );
636
+ $params['content_name'] = $term->name;
637
+ $params['post_id'] = $term->term_id;
638
+
639
+ }
640
+
641
+ pys_add_event( $event_name, $params, $delay );
642
+
643
+ return;
644
+
645
+ }
646
+
647
+ // Custom Post Type
648
+ if ( $on_cpt_enabled && $post_type != 'post' && $post_type != 'page' ) {
649
+
650
+ // skip products and downloads is plugins are activated
651
+ if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
652
+ return;
653
+ }
654
+
655
+ $params['post_type'] = $post_type;
656
+ $params['content_name'] = $post->post_title;
657
+ $params['post_id'] = $post->ID;
658
+
659
+ $taxonomies = get_post_taxonomies( get_post() );
660
+ $terms = pys_get_content_taxonomies( $taxonomies[0] );
661
+ if ( $terms ) {
662
+ $params['content_category'] = $terms;
663
+ }
664
+
665
+ if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
666
+ $params['tags'] = implode( ', ', $tags );
667
+ }
668
+
669
+ pys_add_event( $event_name, $params, $delay );
670
+
671
+ return;
672
+
673
+ }
674
+
675
+ ## WooCommerce Products
676
+ if ( $on_woo_enabled && pys_is_woocommerce_active() && $post_type == 'product' ) {
677
+
678
+ pys_general_woo_event( $post, $track_tags_enabled, $delay, $event_name );
679
+ return;
680
+
681
+ }
682
+
683
+ ## Easy Digital Downloads
684
+ if ( $on_edd_enabled && pys_is_edd_active() && $post_type == 'download' ) {
685
+
686
+ pys_general_edd_event( $post, $track_tags_enabled, $delay, $event_name );
687
+ return;
688
+
689
+ }
690
+
691
+ }
692
+
693
+ }
694
+
695
+ if( ! function_exists( 'pys_search_event' ) ) {
696
+
697
+ function pys_search_event() {
698
+ global $posts;
699
+
700
+ if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
701
+ return;
702
+ }
703
+
704
+ $params = array(
705
+ 'search_string' => $_REQUEST['s']
706
+ );
707
+
708
+ if ( pys_is_woocommerce_active() && pys_get_option( 'woo', 'enabled' )
709
+ && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'product' ) {
710
+
711
+ $content_ids = array();
712
+ $limit = min( count( $posts ), 5 );
713
+
714
+ for ( $i = 0; $i < $limit; $i ++ ) {
715
+ $content_ids = array_merge( pys_get_product_content_id( $posts[ $i ]->ID ), $content_ids );
716
+ }
717
+
718
+ $params['content_ids'] = json_encode( $content_ids );
719
+ $params['content_type'] = 'product';
720
+
721
+ }
722
+
723
+
724
+ pys_add_event( 'Search', $params );
725
+
726
+ }
727
+
728
+ }
729
+
730
+ if( ! function_exists( 'pys_standard_events' ) ) {
731
+
732
+ function pys_standard_events() {
733
+ global $pys_custom_events;
734
+
735
+ $std_events = get_option( 'pixel_your_site_std_events', array() );
736
+
737
+ if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
738
+ return;
739
+ }
740
+
741
+ foreach ( $std_events as $event ) {
742
+
743
+ // skip wrong events
744
+ if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
745
+ continue;
746
+ }
747
+
748
+ // skip if current page does not match URL filter
749
+ if ( pys_match_url( $event['pageurl'] ) == false ) {
750
+ continue;
751
+ }
752
+
753
+ if ( $event['eventtype'] == 'CustomCode' ) {
754
+
755
+ $custom_code = $event['code'];
756
+ $custom_code = stripcslashes( $custom_code );
757
+ $custom_code = trim( $custom_code );
758
+
759
+ // add custom code to global custom events array
760
+ $pys_custom_events[] = $custom_code;
761
+
762
+ } else {
763
+
764
+ $type = $event['eventtype'];
765
+ $params = pys_clean_system_event_params( $event );
766
+
767
+ pys_add_event( $type, $params );
768
+
769
+ }
770
+
771
+ }
772
+
773
+ }
774
+
775
+ }
776
+
777
+ if( !function_exists( 'pys_pixel_init_event' ) ) {
778
+
779
+ function pys_pixel_init_event() {
780
+ global $pys_events;
781
+
782
+ $pys_events[] = array(
783
+ 'type' => 'init',
784
+ 'name' => pys_get_option( 'general', 'pixel_id' ),
785
+ 'params' => pys_pixel_init_params()
786
+ );
787
+
788
+ }
789
+
790
+ }
791
+
792
+ if( ! function_exists( 'pys_output_noscript_code' ) ) {
793
+
794
+ function pys_output_noscript_code() {
795
+ global $pys_events;
796
+
797
+ if( empty( $pys_events ) ) {
798
+ return;
799
+ }
800
+
801
+ foreach( $pys_events as $event ) {
802
+
803
+ $args = array();
804
+
805
+ if( $event['type'] == 'init' ) {
806
+ continue;
807
+ }
808
+
809
+ $args['id'] = pys_get_option( 'general', 'pixel_id' );
810
+ $args['ev'] = $event['name'];
811
+ $args['noscript'] = 1;
812
+
813
+ foreach ( $event['params'] as $param => $value ) {
814
+ @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
815
+ }
816
+
817
+ $src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
818
+
819
+ // note: ALT tag used to pass ADA compliance
820
+ // @see: issue #63 for details
821
+
822
+ echo "<noscript><img height='1' width='1' style='display: none;' src='{$src_attr}' alt='facebook_pixel'></noscript>";
823
+
824
+ }
825
+
826
+ }
827
+
828
+ }
829
+
830
+ if( ! function_exists( 'pys_output_js_events_code' ) ) {
831
+
832
+ function pys_output_js_events_code() {
833
+ global $pys_events;
834
+
835
+ // allow external plugins modify events
836
+ $pys_events = apply_filters( 'pys_prepared_events', $pys_events );
837
+
838
+ if( empty( $pys_events ) ) {
839
+ return;
840
+ }
841
+
842
+ wp_localize_script( 'pys-public', 'pys_events', $pys_events );
843
+
844
+ }
845
+
846
+ }
847
+
848
+ if( ! function_exists( 'pys_output_custom_events_code' ) ) {
849
+
850
+ function pys_output_custom_events_code() {
851
+ global $pys_custom_events;
852
+
853
+ if( empty( $pys_custom_events ) ) {
854
+ return;
855
+ }
856
+
857
+ wp_localize_script( 'pys-public', 'pys_customEvents', $pys_custom_events );
858
+
859
+ }
860
+
861
+ }
862
+
863
+ if( !function_exists( 'pys_clean_system_event_params' ) ) {
864
+
865
+ function pys_clean_system_event_params( $params ) {
866
+
867
+ // remove unused params
868
+ unset( $params['pageurl'] );
869
+ unset( $params['eventtype'] );
870
+ unset( $params['code'] );
871
+ unset( $params['trigger_type'] ); // pro
872
+ unset( $params['custom_currency'] ); // pro
873
+ unset( $params['url'] ); // pro
874
+ unset( $params['css'] ); // pro
875
+ unset( $params['custom_name'] ); // custom events
876
+ unset( $params['scroll_pos'] ); // pro
877
+ unset( $params['url_filter'] ); // pro - dynamic events
878
+
879
+ return $params;
880
+
881
+ }
882
+
883
+ }
884
+
885
+ if( !function_exists( 'pys_get_woo_checkout_params' ) ) {
886
+
887
+ function pys_get_woo_checkout_params( $additional_params_enabled ) {
888
+ global $woocommerce;
889
+
890
+ // set defaults params
891
+ $params = array();
892
+ $params['content_type'] = 'product';
893
+
894
+ $ids = array(); // cart items ids or sku
895
+ $names = ''; // cart items names
896
+ $categories = ''; // cart items categories
897
+
898
+ foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
899
+
900
+ $product_id = pys_get_woo_cart_item_product_id( $item );
901
+ $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
902
+
903
+ // content_name, category_name for each cart item
904
+ if ( $additional_params_enabled ) {
905
+
906
+ $temp = array();
907
+ pys_get_additional_woo_params( $product_id, $temp );
908
+
909
+ $names .= isset( $temp['content_name'] ) ? $temp['content_name'] . ' ' : null;
910
+ $categories .= isset( $temp['category_name'] ) ? $temp['category_name'] . ' ' : null;
911
+
912
+ }
913
+
914
+ }
915
+
916
+ if ( $additional_params_enabled ) {
917
+ $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
918
+ }
919
+
920
+ $params['content_ids'] = json_encode( $ids );
921
+
922
+ if ( ! empty( $names ) ) {
923
+ $params['content_name'] = $names;
924
+ }
925
+
926
+ if ( ! empty( $categories ) ) {
927
+ $params['category_name'] = $categories;
928
+ }
929
+
930
+ return $params;
931
+
932
+ }
933
+
934
+ }
935
+
936
+ if( !function_exists( 'pys_get_default_options' ) ) {
937
+
938
+ function pys_get_default_options() {
939
+
940
+ $options = array();
941
+
942
+ $options['general']['pixel_id'] = '';
943
+ $options['general']['enabled'] = 0;
944
+ $options['general']['add_traffic_source'] = 1;
945
+ $options['general']['enable_advance_matching'] = 1;
946
+ $options['general']['in_footer'] = 0;
947
+
948
+ $options['general']['general_event_enabled'] = 1;
949
+ $options['general']['general_event_name'] = 'GeneralEvent';
950
+ $options['general']['general_event_on_posts_enabled'] = 1;
951
+ $options['general']['general_event_on_pages_enabled'] = 1;
952
+ $options['general']['general_event_on_tax_enabled'] = 1;
953
+ $options['general']['general_event_on_woo_enabled'] = 0;
954
+ $options['general']['general_event_on_edd_enabled'] = 0;
955
+ $options['general']['general_event_add_tags'] = 0;
956
+
957
+ $options['general']['timeonpage_enabled'] = 1;
958
+
959
+ $options['general']['search_event_enabled'] = 1;
960
+
961
+ $options['std']['enabled'] = 0;
962
+
963
+ $options['dyn']['enabled'] = 0;
964
+ $options['dyn']['enabled_on_content'] = 0;
965
+ $options['dyn']['enabled_on_widget'] = 0;
966
+
967
+ $options['woo']['enabled'] = pys_is_woocommerce_active() ? 1 : 0;
968
+
969
+ $options['woo']['content_id'] = 'id';
970
+ $options['woo']['variation_id'] = 'variation';
971
+
972
+ $options['woo']['enable_additional_params'] = 1;
973
+ $options['woo']['enable_tags'] = 1;
974
+ $options['woo']['tax'] = 'incl';
975
+
976
+ $options['woo']['on_view_content'] = 1;
977
+ $options['woo']['enable_view_content_value'] = 1;
978
+ $options['woo']['view_content_value_option'] = 'price';
979
+ $options['woo']['view_content_percent_value'] = '';
980
+ $options['woo']['view_content_global_value'] = '';
981
+
982
+ $options['woo']['on_view_category'] = 1;
983
+
984
+ $options['woo']['on_add_to_cart_btn'] = 1;
985
+ $options['woo']['on_add_to_cart_page'] = 0;
986
+ $options['woo']['on_add_to_cart_checkout'] = 0;
987
+ $options['woo']['enable_add_to_cart_value'] = 1;
988
+ $options['woo']['add_to_cart_value_option'] = 'price';
989
+ $options['woo']['add_to_cart_percent_value'] = '';
990
+ $options['woo']['add_to_cart_global_value'] = '';
991
+
992
+ $options['woo']['on_checkout_page'] = 1;
993
+ $options['woo']['enable_checkout_value'] = 1;
994
+ $options['woo']['checkout_value_option'] = 'price';
995
+ $options['woo']['checkout_percent_value'] = '';
996
+ $options['woo']['checkout_global_value'] = '';
997
+
998
+ $options['woo']['on_thank_you_page'] = 1;
999
+ $options['woo']['enable_purchase_value'] = 1;
1000
+ $options['woo']['purchase_fire_once'] = 1;
1001
+ $options['woo']['purchase_transport'] = 'included';
1002
+ $options['woo']['purchase_value_option'] = 'total';
1003
+ $options['woo']['purchase_percent_value'] = '';
1004
+ $options['woo']['purchase_global_value'] = '';
1005
+
1006
+ $options['woo']['purchase_add_address'] = 1;
1007
+ $options['woo']['purchase_add_payment_method'] = 1;
1008
+ $options['woo']['purchase_add_shipping_method'] = 1;
1009
+ $options['woo']['purchase_add_coupons'] = 1;
1010
+
1011
+ $options['woo']['enable_aff_event'] = 0;
1012
+ $options['woo']['aff_event'] = 'predefined';
1013
+ $options['woo']['aff_predefined_value'] = 'Lead';
1014
+ $options['woo']['aff_custom_value'] = '';
1015
+ $options['woo']['aff_value_option'] = 'none';
1016
+ $options['woo']['aff_global_value'] = '';
1017
+
1018
+ $options['woo']['enable_paypal_event'] = 0;
1019
+ $options['woo']['pp_event'] = 'predefined';
1020
+ $options['woo']['pp_predefined_value'] = 'InitiatePayment';
1021
+ $options['woo']['pp_custom_value'] = '';
1022
+ $options['woo']['pp_value_option'] = 'none';
1023
+ $options['woo']['pp_global_value'] = '';
1024
+
1025
+ /**
1026
+ * Easy Digital Downloads
1027
+ */
1028
+
1029
+ $options['edd']['enabled'] = pys_is_edd_active() ? 1 : 0;
1030
+
1031
+ $options['edd']['content_id'] = 'id';
1032
+ $options['edd']['enable_additional_params'] = 1;
1033
+ $options['edd']['enable_tags'] = 1;
1034
+ $options['edd']['tax'] = 'incl';
1035
+
1036
+ $options['edd']['on_view_content'] = 1;
1037
+ $options['edd']['on_view_content_delay'] = null;
1038
+ $options['edd']['enable_view_content_value'] = 1;
1039
+ $options['edd']['view_content_value_option'] = 'price';
1040
+ $options['edd']['view_content_percent_value'] = null;
1041
+ $options['edd']['view_content_global_value'] = null;
1042
+
1043
+ $options['edd']['on_view_category'] = 1;
1044
+
1045
+ $options['edd']['on_add_to_cart_btn'] = 1;
1046
+ $options['edd']['on_add_to_cart_checkout'] = 0;
1047
+ $options['edd']['enable_add_to_cart_value'] = 1;
1048
+ $options['edd']['add_to_cart_value_option'] = 'price';
1049
+ $options['edd']['add_to_cart_percent_value'] = null;
1050
+ $options['edd']['add_to_cart_global_value'] = null;
1051
+
1052
+ $options['edd']['on_checkout_page'] = 1;
1053
+ $options['edd']['enable_checkout_value'] = 1;
1054
+ $options['edd']['checkout_value_option'] = 'price';
1055
+ $options['edd']['checkout_percent_value'] = null;
1056
+ $options['edd']['checkout_global_value'] = null;
1057
+
1058
+ $options['edd']['on_success_page'] = 1;
1059
+ $options['edd']['enable_purchase_value'] = 1;
1060
+ $options['edd']['purchase_fire_once'] = 1;
1061
+ $options['edd']['purchase_value_option'] = 'total';
1062
+ $options['edd']['purchase_percent_value'] = null;
1063
+ $options['edd']['purchase_global_value'] = null;
1064
+
1065
+ $options['edd']['purchase_add_address'] = true;
1066
+ $options['edd']['purchase_add_payment_method'] = true;
1067
+ $options['edd']['purchase_add_coupons'] = true;
1068
+
1069
+ return apply_filters( 'pys_fb_pixel_setting_defaults', $options );
1070
+
1071
+ }
1072
+
1073
+ }
1074
+
1075
+ if( ! function_exists( 'pys_get_custom_params' ) ) {
1076
+
1077
+ /**
1078
+ * Extract non-system params array
1079
+ */
1080
+ function pys_get_custom_params( $event ) {
1081
+
1082
+ if( !is_array( $event ) || empty( $event ) ) {
1083
+ return array();
1084
+ }
1085
+
1086
+ $system_params = array(
1087
+ 'trigger_type',
1088
+ 'url_filter',
1089
+ 'url',
1090
+ 'css',
1091
+ 'pageurl',
1092
+ 'eventtype',
1093
+ 'value',
1094
+ 'currency',
1095
+ 'custom_currency',
1096
+ 'content_name',
1097
+ 'content_ids',
1098
+ 'content_type',
1099
+ 'content_category',
1100
+ 'num_items',
1101
+ 'order_id',
1102
+ 'search_string',
1103
+ 'status',
1104
+ 'code',
1105
+ 'custom_name',
1106
+ 'scroll_pos'
1107
+ );
1108
+
1109
+ $custom_params = array();
1110
+ foreach( $event as $param => $value ) {
1111
+
1112
+ // skip standard params
1113
+ if( in_array( $param, $system_params ) ) {
1114
+ continue;
1115
+ }
1116
+
1117
+ $custom_params[ $param ] = $value;
1118
+
1119
+ }
1120
+
1121
+
1122
+ return $custom_params;
1123
+
1124
+ }
1125
+
1126
+ }
1127
+
1128
+ if( ! function_exists( 'pys_is_standard_event' ) ) {
1129
+
1130
+ function pys_is_standard_event( $eventtype ) {
1131
+
1132
+ $std_events = array(
1133
+ 'PageView',
1134
+ 'ViewContent',
1135
+ 'Search',
1136
+ 'AddToCart',
1137
+ 'AddToWishlist',
1138
+ 'InitiateCheckout',
1139
+ 'AddPaymentInfo',
1140
+ 'Purchase',
1141
+ 'Lead'
1142
+ );
1143
+
1144
+ return in_array( $eventtype, $std_events );
1145
+
1146
+ }
1147
+
1148
+ }
1149
+
1150
+ if( ! function_exists( 'pys_pixel_init_params' ) ) {
1151
+
1152
+ /**
1153
+ * Add extra params to FB init call.
1154
+ */
1155
+ function pys_pixel_init_params() {
1156
+
1157
+ $params = array();
1158
+ $params = apply_filters( 'pys_pixel_init_params', $params );
1159
+
1160
+ $sanitized = array();
1161
+
1162
+ // sanitize params
1163
+ foreach ( $params as $name => $value ) {
1164
+
1165
+ if ( empty( $value ) ) {
1166
+ continue;
1167
+ }
1168
+
1169
+ $key = esc_js( $name );
1170
+ $sanitized[ $key ] = $value;
1171
+
1172
+ }
1173
+
1174
+ return $sanitized;
1175
+
1176
+ }
1177
+
1178
+ }
1179
+
1180
+ if( ! function_exists( 'pys_woocommerce_events' ) ) {
1181
+
1182
+ function pys_woocommerce_events() {
1183
+
1184
+ if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
1185
+ return;
1186
+ }
1187
+
1188
+ pys_get_woo_code();
1189
+
1190
+ // Woo AddToCart on Button
1191
+ if ( pys_get_option( 'woo', 'on_add_to_cart_btn' ) ) {
1192
+ add_action( 'woocommerce_after_shop_loop_item', 'pys_add_woo_loop_product_data' );
1193
+ add_action( 'woocommerce_after_add_to_cart_button', 'pys_add_woo_single_product_data' );
1194
+ }
1195
+
1196
+ }
1197
+
1198
+ }
1199
+
1200
+ if( ! function_exists( 'pys_output_options' ) ) {
1201
+
1202
+ function pys_output_options() {
1203
+
1204
+ $options = array(
1205
+ 'site_url' => get_site_url(),
1206
+ 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1207
+ );
1208
+
1209
+ wp_localize_script( 'pys-public', 'pys_options', $options );
1210
+
1211
+ }
1212
+
1213
+ }
1214
+
1215
+ if( ! function_exists( 'pys_head_comments' ) ) {
1216
+
1217
+ function pys_head_comments() {
1218
+
1219
+ if( defined( 'PYS_PRO_VERSION' ) ) {
1220
+ $version = "PRO v" . PYS_PRO_VERSION;
1221
+ } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1222
+ $version = "FREE v" . PYS_FREE_VERSION;
1223
+ } else {
1224
+ $version = null;
1225
+ }
1226
+
1227
+ ?>
1228
+
1229
+ <!-- Facebook Pixel code is added on this page by PixelYourSite <?php echo esc_attr( $version ); ?> plugin. You can test it with Pixel Helper Chrome Extension. -->
1230
+
1231
+ <?php
1232
+ }
1233
+
1234
+ }
1235
+
1236
+ if( ! function_exists( 'pys_render_event_code' ) ) {
1237
+
1238
+ /**
1239
+ * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1240
+ */
1241
+ function pys_render_event_code( $event_name, $params ) {
1242
+
1243
+ $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1244
+
1245
+ $params = pys_clean_system_event_params( $params );
1246
+
1247
+ $event_params = '';
1248
+ foreach( $params as $name => $value ) {
1249
+
1250
+ if( empty( $value ) && $value !== "0" ) {
1251
+ continue;
1252
+ }
1253
+
1254
+ $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1255
+
1256
+ }
1257
+
1258
+ $event_params = ltrim( $event_params );
1259
+ $event_params = rtrim( $event_params, "," );
1260
+
1261
+ return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1262
+
1263
+ }
1264
+
1265
+ }
1266
+
1267
+ if( !function_exists( 'pys_add_domain_param' ) ) {
1268
+
1269
+ function pys_add_domain_param( $params, $event ) {
1270
+
1271
+ // get home URL without protocol
1272
+ $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1273
+ return $params;
1274
+
1275
+ }
1276
+
1277
+ }
1278
+
1279
+ if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
1280
+
1281
+ function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
1282
+
1283
+ // get WP_Post object
1284
+ if ( is_numeric( $post ) ) {
1285
+ $id = absint( $post );
1286
+ $_post = get_post( $id );
1287
+ } elseif ( $post instanceof WC_Product ) {
1288
+ $_post = $post->post;
1289
+ } elseif ( isset( $post->ID ) ) {
1290
+ $_post = $post;
1291
+ } else {
1292
+ return;
1293
+ }
1294
+
1295
+ $params['content_name'] = $_post->post_title;
1296
+
1297
+ $terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
1298
+ if ( $terms ) {
1299
+ $params['category_name'] = $terms;
1300
+ }
1301
+
1302
+ }
1303
+
1304
+ }
1305
+
1306
+ if ( ! function_exists( 'pys_get_object_tags' ) ) {
1307
+
1308
+ /**
1309
+ * @param int|WP_Post $post Post ID or object
1310
+ * @param string $taxonomy Taxonomy name
1311
+ *
1312
+ * @return array Array of terms titles on success or empty array
1313
+ */
1314
+ function pys_get_object_tags( $post, $taxonomy ) {
1315
+
1316
+ $tags = array();
1317
+ $terms = get_the_terms( $post, $taxonomy );
1318
+
1319
+ if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1320
+
1321
+ foreach ( $terms as $term ) {
1322
+ $tags[] = html_entity_decode( $term->name );
1323
+ }
1324
+
1325
+ }
1326
+
1327
+ return $tags;
1328
+
1329
+ }
1330
+
1331
+ }
1332
+
1333
+ if ( ! function_exists( 'pys_delete_events' ) ) {
1334
+
1335
+ function pys_delete_events( $events_ids, $events_type ) {
1336
+
1337
+ if ( $events_type == 'standard' ) {
1338
+ $option_name = 'pixel_your_site_std_events';
1339
+ } else {
1340
+ $option_name = 'pixel_your_site_dyn_events';
1341
+ }
1342
+
1343
+ $events = (array) get_option( $option_name );
1344
+
1345
+ if ( empty( $events ) ) {
1346
+ return;
1347
+ }
1348
+
1349
+ foreach ( $events_ids as $id ) {
1350
+ unset( $events[ $id ] );
1351
+ }
1352
+
1353
+ update_option( $option_name, $events );
1354
+
1355
+ }
1356
+
1357
+ }
1358
+
1359
+ if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
1360
+
1361
+ function pys_is_wc_version_gte( $version ) {
1362
+
1363
+ if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
1364
+ return version_compare( WC_VERSION, $version, '>=' );
1365
+ } else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
1366
+ return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
1367
+ } else {
1368
+ return false;
1369
+ }
1370
+
1371
+ }
1372
+
1373
+ }
1374
+
1375
+ if ( ! function_exists( 'pys_woo_product_is_type' ) ) {
1376
+
1377
+ /**
1378
+ * @param \WC_Product|\WP_Post $product
1379
+ *
1380
+ * @return bool
1381
+ */
1382
+ function pys_woo_product_is_type( $product, $type ) {
1383
+
1384
+ if ( pys_is_wc_version_gte( '2.7' ) ) {
1385
+ return $type == $product->is_type( $type );
1386
+ } else {
1387
+ return $product->product_type == $type;
1388
+ }
1389
+
1390
+ }
1391
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1392
  }
inc/core-edd.php CHANGED
@@ -1,262 +1,262 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- if ( ! function_exists( 'pys_edd_events' ) ) {
8
-
9
- function pys_edd_events() {
10
- global $post, $posts;
11
-
12
- if ( pys_get_option( 'edd', 'enabled' ) == false || pys_is_edd_active() == false ) {
13
- return;
14
- }
15
-
16
- // set defaults params
17
- $params = array();
18
- $params['content_type'] = 'product';
19
-
20
- // ViewContent Event
21
- if ( pys_get_option( 'edd', 'on_view_content' ) && is_singular( array( 'download' ) ) ) {
22
-
23
- $params['content_ids'] = "['" . pys_get_edd_content_id( $post->ID ) . "']";
24
-
25
- // currency, value
26
- if ( pys_get_option( 'edd', 'enable_view_content_value' ) ) {
27
-
28
- $params['value'] = pys_get_option( 'edd', 'view_content_global_value' );
29
- $params['currency'] = edd_get_currency();
30
-
31
- }
32
-
33
- // contents
34
- $params['contents'] = json_encode( array(
35
- array(
36
- 'id' => (string) $post->ID,
37
- 'quantity' => 1,
38
- )
39
- ) );
40
-
41
- pys_add_event( 'ViewContent', $params, 0 );
42
-
43
- return;
44
-
45
- }
46
-
47
- // ViewCategory
48
- if ( pys_get_option( 'edd', 'on_view_category', true ) && is_tax( 'download_category' ) ) {
49
-
50
- $term = get_term_by( 'slug', get_query_var( 'term' ), 'download_category' );
51
- $params['content_name'] = $term->name;
52
-
53
- $parent_ids = get_ancestors( $term->term_id, 'download_category', 'taxonomy' );
54
- $params['content_category'] = array();
55
-
56
- foreach ( $parent_ids as $term_id ) {
57
- $term = get_term_by( 'id', $term_id, 'download_category' );
58
- $params['content_category'][] = $term->name;
59
- }
60
-
61
- $params['content_category'] = implode( ',', $params['content_category'] );
62
-
63
- $content_ids = array();
64
- $limit = min( count( $posts ), 5 );
65
-
66
- for ( $i = 0; $i < $limit; $i ++ ) {
67
- $content_ids[] = (string) $posts[ $i ]->ID;
68
- }
69
-
70
- $params['content_ids'] = json_encode( $content_ids );
71
- $params['content_type'] = 'product';
72
-
73
- pys_add_event( 'ViewCategory', $params );
74
-
75
- return;
76
-
77
- }
78
-
79
- /**
80
- * AddToCart Event (button)
81
- *
82
- * @see pys_edd_purchase_link_args()
83
- */
84
-
85
- // AddToCart on Checkout page
86
- if ( pys_get_option( 'edd', 'on_add_to_cart_checkout' ) && edd_is_checkout() ) {
87
-
88
- $ids = array();
89
- $contents = array();
90
-
91
- foreach ( edd_get_cart_contents() as $cart_item ) {
92
-
93
- $download_id = intval( $cart_item['id'] );
94
- $ids[] = (string) pys_get_edd_content_id( $download_id );
95
-
96
- // contents
97
- $contents[] = array(
98
- 'id' => (string) $download_id,
99
- 'quantity' => $cart_item['quantity']
100
- );
101
-
102
- }
103
-
104
- $params['content_ids'] = json_encode( $ids );
105
- $params['contents'] = json_encode( $contents );
106
-
107
- // currency, value
108
- if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
109
-
110
- $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
111
- $params['currency'] = edd_get_currency();
112
-
113
- }
114
-
115
- pys_add_event( 'AddToCart', $params );
116
-
117
- }
118
-
119
- // InitiateCheckout Event
120
- if ( pys_get_option( 'edd', 'on_checkout_page' ) && edd_is_checkout() ) {
121
-
122
- $ids = array();
123
-
124
- foreach ( edd_get_cart_contents() as $cart_item ) {
125
-
126
- $download_id = intval( $cart_item['id'] );
127
- $ids[] = pys_get_edd_content_id( $download_id );
128
-
129
- }
130
-
131
- $params['content_ids'] = "'[" . implode( "','", $ids ) . "']";
132
-
133
- // currency, value
134
- if ( pys_get_option( 'edd', 'enable_checkout_value' ) ) {
135
-
136
- $params['value'] = pys_get_option( 'edd', 'checkout_global_value' );
137
- $params['currency'] = edd_get_currency();
138
-
139
- }
140
-
141
- pys_add_event( 'InitiateCheckout', $params );
142
-
143
- return;
144
-
145
- }
146
-
147
- // Purchase Event
148
- if ( pys_get_option( 'edd', 'on_success_page' ) && edd_is_success_page() ) {
149
-
150
- ## skip payment confirmation page
151
- if( isset( $_GET['payment-confirmation'] ) ) {
152
- return;
153
- }
154
-
155
- global $edd_receipt_args;
156
-
157
- $session = edd_get_purchase_session();
158
- if ( isset( $_GET['payment_key'] ) ) {
159
- $payment_key = urldecode( $_GET['payment_key'] );
160
- } else if ( $session ) {
161
- $payment_key = $session['purchase_key'];
162
- } elseif ( $edd_receipt_args['payment_key'] ) {
163
- $payment_key = $edd_receipt_args['payment_key'];
164
- }
165
-
166
- if ( ! isset( $payment_key ) ) {
167
- return;
168
- }
169
-
170
- $payment_id = edd_get_purchase_id_by_key( $payment_key );
171
- $user_can_view = edd_can_view_receipt( $payment_key );
172
-
173
- if ( ! $user_can_view && ! empty( $payment_key ) && ! is_user_logged_in() && ! edd_is_guest_payment( $payment_id ) ) {
174
- return;
175
- }
176
-
177
- $cart = edd_get_payment_meta_cart_details( $payment_id, true );
178
- $status = edd_get_payment_status( $payment_id, true );
179
-
180
- ## pending payment status used because we can't fire event on IPN
181
- if( strtolower( $status ) != 'complete' && strtolower( $status ) != 'pending' ) {
182
- return;
183
- }
184
-
185
- $ids = array();
186
- $contents = array();
187
-
188
- foreach ( $cart as $cart_item ) {
189
-
190
- $download_id = intval( $cart_item['id'] );
191
- $ids[] = (string) pys_get_edd_content_id( $download_id );
192
-
193
- // contents
194
- $contents[] = array(
195
- 'id' => (string) $download_id,
196
- 'quantity' => $cart_item['quantity']
197
- );
198
-
199
- }
200
-
201
- $params['content_ids'] = json_encode( $ids );
202
- $params['contents'] = json_encode( $contents );
203
-
204
- // currency, value
205
- if ( pys_get_option( 'edd', 'enable_purchase_value' ) ) {
206
-
207
- $params['value'] = pys_get_option( 'edd', 'purchase_global_value' );
208
- $params['currency'] = edd_get_currency();
209
-
210
- }
211
-
212
- pys_add_event( 'Purchase', $params );
213
-
214
- return;
215
-
216
- }
217
-
218
- }
219
-
220
- }
221
-
222
- if ( ! function_exists( 'pys_edd_purchase_link_args' ) ) {
223
-
224
- function pys_edd_purchase_link_args( $args = array() ) {
225
- global $pys_edd_ajax_events;
226
-
227
- $download_id = $args['download_id'];
228
- $content_id = (string) pys_get_edd_content_id( $download_id );
229
-
230
- $event_id = uniqid();
231
-
232
- $params = array();
233
- $params['content_type'] = 'product';
234
- $params['content_ids'] = json_encode( array( $content_id ) );
235
-
236
- // currency, value
237
- if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
238
-
239
- $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
240
- $params['currency'] = edd_get_currency();
241
-
242
- }
243
-
244
- // contents
245
- $params['contents'] = json_encode( array(
246
- 'id' => (string) $content_id,
247
- 'quantity' => 1,
248
- ) );
249
-
250
- $pys_edd_ajax_events[ $event_id ] = array(
251
- 'name' => 'AddToCart',
252
- 'params' => $params
253
- );
254
-
255
- $classes = isset( $args['class'] ) ? $args['class'] : null;
256
- $args['class'] = $classes . " pys-event-id-{$event_id}";
257
-
258
- return $args;
259
-
260
- }
261
-
262
  }
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ if ( ! function_exists( 'pys_edd_events' ) ) {
8
+
9
+ function pys_edd_events() {
10
+ global $post, $posts;
11
+
12
+ if ( pys_get_option( 'edd', 'enabled' ) == false || pys_is_edd_active() == false ) {
13
+ return;
14
+ }
15
+
16
+ // set defaults params
17
+ $params = array();
18
+ $params['content_type'] = 'product';
19
+
20
+ // ViewContent Event
21
+ if ( pys_get_option( 'edd', 'on_view_content' ) && is_singular( array( 'download' ) ) ) {
22
+
23
+ $params['content_ids'] = "['" . pys_get_edd_content_id( $post->ID ) . "']";
24
+
25
+ // currency, value
26
+ if ( pys_get_option( 'edd', 'enable_view_content_value' ) ) {
27
+
28
+ $params['value'] = pys_get_option( 'edd', 'view_content_global_value' );
29
+ $params['currency'] = edd_get_currency();
30
+
31
+ }
32
+
33
+ // contents
34
+ $params['contents'] = json_encode( array(
35
+ array(
36
+ 'id' => (string) $post->ID,
37
+ 'quantity' => 1,
38
+ )
39
+ ) );
40
+
41
+ pys_add_event( 'ViewContent', $params, 0 );
42
+
43
+ return;
44
+
45
+ }
46
+
47
+ // ViewCategory
48
+ if ( pys_get_option( 'edd', 'on_view_category', true ) && is_tax( 'download_category' ) ) {
49
+
50
+ $term = get_term_by( 'slug', get_query_var( 'term' ), 'download_category' );
51
+ $params['content_name'] = $term->name;
52
+
53
+ $parent_ids = get_ancestors( $term->term_id, 'download_category', 'taxonomy' );
54
+ $params['content_category'] = array();
55
+
56
+ foreach ( $parent_ids as $term_id ) {
57
+ $term = get_term_by( 'id', $term_id, 'download_category' );
58
+ $params['content_category'][] = $term->name;
59
+ }
60
+
61
+ $params['content_category'] = implode( ',', $params['content_category'] );
62
+
63
+ $content_ids = array();
64
+ $limit = min( count( $posts ), 5 );
65
+
66
+ for ( $i = 0; $i < $limit; $i ++ ) {
67
+ $content_ids[] = (string) $posts[ $i ]->ID;
68
+ }
69
+
70
+ $params['content_ids'] = json_encode( $content_ids );
71
+ $params['content_type'] = 'product';
72
+
73
+ pys_add_event( 'ViewCategory', $params );
74
+
75
+ return;
76
+
77
+ }
78
+
79
+ /**
80
+ * AddToCart Event (button)
81
+ *
82
+ * @see pys_edd_purchase_link_args()
83
+ */
84
+
85
+ // AddToCart on Checkout page
86
+ if ( pys_get_option( 'edd', 'on_add_to_cart_checkout' ) && edd_is_checkout() ) {
87
+
88
+ $ids = array();
89
+ $contents = array();
90
+
91
+ foreach ( edd_get_cart_contents() as $cart_item ) {
92
+
93
+ $download_id = intval( $cart_item['id'] );
94
+ $ids[] = (string) pys_get_edd_content_id( $download_id );
95
+
96
+ // contents
97
+ $contents[] = array(
98
+ 'id' => (string) $download_id,
99
+ 'quantity' => $cart_item['quantity']
100
+ );
101
+
102
+ }
103
+
104
+ $params['content_ids'] = json_encode( $ids );
105
+ $params['contents'] = json_encode( $contents );
106
+
107
+ // currency, value
108
+ if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
109
+
110
+ $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
111
+ $params['currency'] = edd_get_currency();
112
+
113
+ }
114
+
115
+ pys_add_event( 'AddToCart', $params );
116
+
117
+ }
118
+
119
+ // InitiateCheckout Event
120
+ if ( pys_get_option( 'edd', 'on_checkout_page' ) && edd_is_checkout() ) {
121
+
122
+ $ids = array();
123
+
124
+ foreach ( edd_get_cart_contents() as $cart_item ) {
125
+
126
+ $download_id = intval( $cart_item['id'] );
127
+ $ids[] = pys_get_edd_content_id( $download_id );
128
+
129
+ }
130
+
131
+ $params['content_ids'] = "'[" . implode( "','", $ids ) . "']";
132
+
133
+ // currency, value
134
+ if ( pys_get_option( 'edd', 'enable_checkout_value' ) ) {
135
+
136
+ $params['value'] = pys_get_option( 'edd', 'checkout_global_value' );
137
+ $params['currency'] = edd_get_currency();
138
+
139
+ }
140
+
141
+ pys_add_event( 'InitiateCheckout', $params );
142
+
143
+ return;
144
+
145
+ }
146
+
147
+ // Purchase Event
148
+ if ( pys_get_option( 'edd', 'on_success_page' ) && edd_is_success_page() ) {
149
+
150
+ ## skip payment confirmation page
151
+ if( isset( $_GET['payment-confirmation'] ) ) {
152
+ return;
153
+ }
154
+
155
+ global $edd_receipt_args;
156
+
157
+ $session = edd_get_purchase_session();
158
+ if ( isset( $_GET['payment_key'] ) ) {
159
+ $payment_key = urldecode( $_GET['payment_key'] );
160
+ } else if ( $session ) {
161
+ $payment_key = $session['purchase_key'];
162
+ } elseif ( $edd_receipt_args['payment_key'] ) {
163
+ $payment_key = $edd_receipt_args['payment_key'];
164
+ }
165
+
166
+ if ( ! isset( $payment_key ) ) {
167
+ return;
168
+ }
169
+
170
+ $payment_id = edd_get_purchase_id_by_key( $payment_key );
171
+ $user_can_view = edd_can_view_receipt( $payment_key );
172
+
173
+ if ( ! $user_can_view && ! empty( $payment_key ) && ! is_user_logged_in() && ! edd_is_guest_payment( $payment_id ) ) {
174
+ return;
175
+ }
176
+
177
+ $cart = edd_get_payment_meta_cart_details( $payment_id, true );
178
+ $status = edd_get_payment_status( $payment_id, true );
179
+
180
+ ## pending payment status used because we can't fire event on IPN
181
+ if( strtolower( $status ) != 'complete' && strtolower( $status ) != 'pending' ) {
182
+ return;
183
+ }
184
+
185
+ $ids = array();
186
+ $contents = array();
187
+
188
+ foreach ( $cart as $cart_item ) {
189
+
190
+ $download_id = intval( $cart_item['id'] );
191
+ $ids[] = (string) pys_get_edd_content_id( $download_id );
192
+
193
+ // contents
194
+ $contents[] = array(
195
+ 'id' => (string) $download_id,
196
+ 'quantity' => $cart_item['quantity']
197
+ );
198
+
199
+ }
200
+
201
+ $params['content_ids'] = json_encode( $ids );
202
+ $params['contents'] = json_encode( $contents );
203
+
204
+ // currency, value
205
+ if ( pys_get_option( 'edd', 'enable_purchase_value' ) ) {
206
+
207
+ $params['value'] = pys_get_option( 'edd', 'purchase_global_value' );
208
+ $params['currency'] = edd_get_currency();
209
+
210
+ }
211
+
212
+ pys_add_event( 'Purchase', $params );
213
+
214
+ return;
215
+
216
+ }
217
+
218
+ }
219
+
220
+ }
221
+
222
+ if ( ! function_exists( 'pys_edd_purchase_link_args' ) ) {
223
+
224
+ function pys_edd_purchase_link_args( $args = array() ) {
225
+ global $pys_edd_ajax_events;
226
+
227
+ $download_id = $args['download_id'];
228
+ $content_id = (string) pys_get_edd_content_id( $download_id );
229
+
230
+ $event_id = uniqid();
231
+
232
+ $params = array();
233
+ $params['content_type'] = 'product';
234
+ $params['content_ids'] = json_encode( array( $content_id ) );
235
+
236
+ // currency, value
237
+ if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
238
+
239
+ $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
240
+ $params['currency'] = edd_get_currency();
241
+
242
+ }
243
+
244
+ // contents
245
+ $params['contents'] = json_encode( array(
246
+ 'id' => (string) $content_id,
247
+ 'quantity' => 1,
248
+ ) );
249
+
250
+ $pys_edd_ajax_events[ $event_id ] = array(
251
+ 'name' => 'AddToCart',
252
+ 'params' => $params
253
+ );
254
+
255
+ $classes = isset( $args['class'] ) ? $args['class'] : null;
256
+ $args['class'] = $classes . " pys-event-id-{$event_id}";
257
+
258
+ return $args;
259
+
260
+ }
261
+
262
  }
inc/core.php CHANGED
@@ -1,559 +1,634 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- function pys_get_woo_product_price_to_display( $product_id, $qty = 1 ) {
8
-
9
- if ( ! $product = wc_get_product( $product_id ) ) {
10
- return 0;
11
- }
12
-
13
- if ( pys_is_wc_version_gte( '2.7' ) ) {
14
-
15
- return wc_get_price_to_display( $product, array( 'qty' => $qty ) );
16
-
17
- } else {
18
-
19
- return 'incl' === get_option( 'woocommerce_tax_display_shop' )
20
- ? $product->get_price_including_tax( $qty )
21
- : $product->get_price_excluding_tax( $qty );
22
-
23
- }
24
-
25
- }
26
-
27
- if ( ! function_exists( 'pys_get_woo_product_addtocart_params' ) ) {
28
-
29
- function pys_get_woo_product_addtocart_params( $product_id, $qty = 1 ) {
30
-
31
- $content_id = pys_get_product_content_id( $product_id );
32
-
33
- $params = array();
34
- $params['content_type'] = 'product';
35
- $params['content_ids'] = json_encode( $content_id );
36
-
37
- // currency, value
38
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
39
-
40
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
41
- switch ( $option ) {
42
- case 'global':
43
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
44
- break;
45
-
46
- case 'price':
47
- $value = pys_get_product_price( $product_id, $qty );
48
- break;
49
-
50
- default:
51
- $value = null;
52
- }
53
-
54
- $params['value'] = $value;
55
- $params['currency'] = get_woocommerce_currency();
56
-
57
- }
58
-
59
- // contents
60
- $params['contents'] = json_encode( array(
61
- array(
62
- 'id' => (string) reset( $content_id ),
63
- 'quantity' => $qty,
64
- 'item_price' => pys_get_woo_product_price_to_display( $product_id ),
65
- )
66
- ) );
67
-
68
- return $params;
69
-
70
- }
71
-
72
- }
73
-
74
- if ( ! function_exists( 'pys_get_post_tags' ) ) {
75
-
76
- /**
77
- * Return array of product tags.
78
- * PRO only.
79
- */
80
- function pys_get_post_tags( $post_id ) {
81
-
82
- return array(); // PRO feature
83
-
84
- }
85
-
86
- }
87
-
88
- if ( ! function_exists( 'pys_get_woo_code' ) ) {
89
-
90
- /**
91
- * Build WooCommerce related events code.
92
- * Function adds evaluated event params to global array.
93
- */
94
- function pys_get_woo_code() {
95
- global $post, $posts, $woocommerce;
96
-
97
- // set defaults params
98
- $params = array();
99
- $params['content_type'] = 'product';
100
-
101
- // ViewContent Event
102
- if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
103
-
104
- $product = wc_get_product( $post->ID );
105
-
106
- $content_id = pys_get_product_content_id( $post->ID );
107
- $params['content_ids'] = json_encode( $content_id );
108
-
109
- if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
110
- $params['content_type'] = 'product_group';
111
- } else {
112
- $params['content_type'] = 'product';
113
- }
114
-
115
- // @since 5.0.6
116
- $params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
117
- $product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
118
-
119
- // currency, value
120
- if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
121
-
122
- $option = pys_get_option( 'woo', 'view_content_value_option' );
123
- switch ( $option ) {
124
- case 'global':
125
- $value = pys_get_option( 'woo', 'view_content_global_value' );
126
- break;
127
-
128
- case 'price':
129
- $value = pys_get_product_price( $post );
130
- break;
131
-
132
- default:
133
- $value = null;
134
- }
135
-
136
- $params['value'] = $value;
137
- $params['currency'] = get_woocommerce_currency();
138
-
139
- }
140
-
141
- // contents
142
- $params['contents'] = json_encode( array(
143
- array(
144
- 'id' => (string) reset( $content_id ),
145
- 'quantity' => 1,
146
- 'item_price' => pys_get_woo_product_price_to_display( $post->ID ),
147
- )
148
- ) );
149
-
150
- pys_add_event( 'ViewContent', $params );
151
-
152
- return;
153
-
154
- }
155
-
156
- // ViewCategory
157
- if ( pys_get_option( 'woo', 'on_view_category', true ) && is_tax( 'product_cat' ) ) {
158
-
159
- $term = get_term_by( 'slug', get_query_var( 'term' ), 'product_cat' );
160
- $params['content_name'] = $term->name;
161
-
162
- $parent_ids = get_ancestors( $term->term_id, 'product_cat', 'taxonomy' );
163
- $params['content_category'] = array();
164
-
165
- foreach ( $parent_ids as $term_id ) {
166
- $term = get_term_by( 'id', $term_id, 'product_cat' );
167
- $params['content_category'][] = $term->name;
168
- }
169
-
170
- $params['content_category'] = implode( ',', $params['content_category'] );
171
-
172
- $content_ids = array();
173
- $limit = min( count( $posts ), 5 );
174
-
175
- for ( $i = 0; $i < $limit; $i ++ ) {
176
- $content_ids = array_merge( pys_get_product_content_id( $posts[ $i ]->ID ), $content_ids );
177
- }
178
-
179
- $params['content_ids'] = json_encode( $content_ids );
180
-
181
- pys_add_event( 'ViewCategory', $params );
182
-
183
- return;
184
-
185
- }
186
-
187
- // AddToCart Cart Page Event
188
- if ( is_cart() && ( pys_get_option( 'woo', 'on_add_to_cart_page' ) || get_option( 'woocommerce_cart_redirect_after_add' ) === 'yes' ) ) {
189
-
190
- $ids = array(); // cart items ids or sku
191
- $contents = array();
192
-
193
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
194
-
195
- $product_id = pys_get_woo_cart_item_product_id( $item );
196
- $content_id = pys_get_product_content_id( $product_id );
197
- $ids = array_merge( $ids, $content_id );
198
-
199
- // raw product id
200
- $_product_id = empty( $item['variation_id'] ) ? $item['product_id']
201
- : $item['variation_id'];
202
-
203
- // contents
204
- $contents[] = array(
205
- 'id' => (string) reset( $content_id ),
206
- 'quantity' => $item['quantity'],
207
- 'item_price' => pys_get_woo_product_price_to_display( $_product_id ),
208
- );
209
-
210
- }
211
-
212
- $params['content_ids'] = json_encode( $ids );
213
- $params['contents'] = json_encode( $contents );
214
-
215
- // currency, value
216
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
217
-
218
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
219
- switch ( $option ) {
220
- case 'global':
221
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
222
- break;
223
-
224
- case 'price':
225
- $value = pys_get_cart_total();
226
- break;
227
-
228
- default:
229
- $value = null;
230
- }
231
-
232
- $params['value'] = $value;
233
- $params['currency'] = get_woocommerce_currency();
234
-
235
- }
236
-
237
- pys_add_event( 'AddToCart', $params );
238
-
239
- return;
240
-
241
- }
242
-
243
- // AddToCart on Checkout page
244
- if ( pys_get_option( 'woo', 'on_add_to_cart_checkout' ) && is_checkout() && ! is_wc_endpoint_url() ) {
245
-
246
- $ids = array(); // cart items ids or sku
247
- $contents = array();
248
-
249
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
250
-
251
- $product_id = pys_get_woo_cart_item_product_id( $item );
252
- $content_id = pys_get_product_content_id( $product_id );
253
- $ids = array_merge( $ids, $content_id );
254
-
255
- // raw product id
256
- $_product_id = empty( $item['variation_id'] ) ? $item['product_id']
257
- : $item['variation_id'];
258
-
259
- // contents
260
- $contents[] = array(
261
- 'id' => (string) reset( $content_id ),
262
- 'quantity' => $item['quantity'],
263
- 'item_price' => pys_get_woo_product_price_to_display( $_product_id ),
264
- );
265
-
266
- }
267
-
268
- $params['content_ids'] = json_encode( $ids );
269
- $params['contents'] = json_encode( $contents );
270
-
271
- // currency, value
272
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
273
-
274
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
275
- switch ( $option ) {
276
- case 'global':
277
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
278
- break;
279
-
280
- case 'price':
281
- $value = pys_get_cart_total();
282
- break;
283
-
284
- default:
285
- $value = null;
286
- }
287
-
288
- $params['value'] = $value;
289
- $params['currency'] = get_woocommerce_currency();
290
-
291
- }
292
-
293
- pys_add_event( 'AddToCart', $params );
294
-
295
- }
296
-
297
- // Checkout Page Event
298
- if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
299
-
300
- $params = pys_get_woo_checkout_params( false );
301
-
302
- // currency, value
303
- if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
304
-
305
- $option = pys_get_option( 'woo', 'checkout_value_option' );
306
- switch ( $option ) {
307
- case 'global':
308
- $value = pys_get_option( 'woo', 'checkout_global_value' );
309
- break;
310
-
311
- case 'price':
312
- $value = pys_get_cart_total();
313
- break;
314
-
315
- default:
316
- $value = null;
317
- }
318
-
319
- $params['value'] = $value;
320
- $params['currency'] = get_woocommerce_currency();
321
-
322
- }
323
-
324
- pys_add_event( 'InitiateCheckout', $params );
325
-
326
- return;
327
-
328
- }
329
-
330
- // Purchase Event
331
- if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_order_received_page() && isset( $_REQUEST['key'] ) ) {
332
-
333
- $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
334
- $order = new WC_Order( $order_id );
335
- $items = $order->get_items( 'line_item' );
336
-
337
- $ids = array(); // order items ids or sku
338
- $contents = array();
339
-
340
- foreach ( $items as $item ) {
341
-
342
- $product_id = pys_get_woo_cart_item_product_id( $item );
343
- $content_id = pys_get_product_content_id( $product_id );
344
- $ids = array_merge( $ids, $content_id );
345
-
346
- // raw product id
347
- $_product_id = empty( $item['variation_id'] ) ? $item['product_id']
348
- : $item['variation_id'];
349
-
350
- // contents
351
- $contents[] = array(
352
- 'id' => (string) reset( $content_id ),
353
- 'quantity' => $item['quantity'],
354
- 'item_price' => pys_get_woo_product_price_to_display( $_product_id ),
355
- );
356
-
357
- }
358
-
359
- $params['content_ids'] = json_encode( $ids );
360
- $params['contents'] = json_encode( $contents );
361
-
362
- // currency, value
363
- if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
364
-
365
- $option = pys_get_option( 'woo', 'purchase_value_option' );
366
- switch ( $option ) {
367
- case 'global':
368
- $value = pys_get_option( 'woo', 'purchase_global_value' );
369
- break;
370
-
371
- case 'total':
372
- $value = pys_get_order_total( $order );
373
- break;
374
-
375
- default:
376
- $value = null;
377
- }
378
-
379
- $params['value'] = $value;
380
- $params['currency'] = get_woocommerce_currency();
381
-
382
- }
383
-
384
- pys_add_event( 'Purchase', $params );
385
-
386
- return;
387
-
388
- }
389
-
390
- }
391
-
392
- }
393
-
394
- if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
395
-
396
- /**
397
- * Adds extra params to pixel init code. On Free always returns empty string.
398
- * PRO only.
399
- *
400
- * @see: https://www.facebook.com/help/ipad-app/606443329504150
401
- * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
402
- * @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
403
- *
404
- * @return string
405
- */
406
- function pys_get_additional_matching_code() {
407
-
408
- return ''; // PRO feature
409
-
410
- }
411
-
412
- }
413
-
414
- if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
415
-
416
- /**
417
- * Adds additional post parameters like `content_name` and `category_name`.
418
- * PRO only.
419
- *
420
- * @param $post WP_Post|int
421
- * @param $params array reference to $params array
422
- */
423
- function pys_get_additional_woo_params( $post, &$params ) {
424
-
425
- // PRO only
426
-
427
- }
428
-
429
- }
430
-
431
- if ( ! function_exists( 'pys_general_woo_event' ) ) {
432
-
433
- /**
434
- * Add General event on Woo Product page. PRO only.
435
- *
436
- * @param $post WP_Post|int
437
- * @param $track_tags bool
438
- * @param $delay int
439
- * @param $event_name string
440
- */
441
- function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
442
- // PRO feature
443
- }
444
-
445
- }
446
-
447
- if ( ! function_exists( 'pys_general_edd_event' ) ) {
448
-
449
- /**
450
- * Add General event on EDD Download page. PRO only.
451
- *
452
- * @param $post WP_Post|int
453
- * @param $track_tags bool
454
- * @param $delay int
455
- * @param $event_name string
456
- */
457
- function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
458
- // PRO feature
459
- }
460
-
461
- }
462
-
463
- if ( ! function_exists( 'pys_get_product_price' ) ) {
464
-
465
- /**
466
- * Return product price depends on plugin, product and WooCommerce settings.
467
- *
468
- * @param $product_id
469
- *
470
- * @return null|int Product price
471
- */
472
- function pys_get_product_price( $product_id, $qty = 1 ) {
473
-
474
- $product = wc_get_product( $product_id );
475
-
476
- if ( false == $product instanceof WC_Product ) {
477
- return 0;
478
- }
479
-
480
- if ( $product->is_taxable() ) {
481
-
482
- if ( pys_is_wc_version_gte( '3.0' ) ) {
483
- $value = wc_get_price_including_tax( $product, array( 'price' => $product->get_price(), 'qty' => $qty ) );
484
- } else {
485
- $value = $product->get_price_including_tax( $qty, $product->get_price() );
486
- }
487
-
488
- } else {
489
-
490
- if ( pys_is_wc_version_gte( '3.0' ) ) {
491
- $value = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_price(), 'qty' => $qty ) );
492
- } else {
493
- $value = $product->get_price_excluding_tax( $qty, $product->get_price() );
494
- }
495
-
496
- }
497
-
498
- return $value;
499
-
500
- }
501
-
502
- }
503
-
504
- if ( ! function_exists( 'pys_get_cart_total' ) ) {
505
-
506
- function pys_get_cart_total() {
507
- global $woocommerce;
508
-
509
- return $woocommerce->cart->subtotal;
510
-
511
- }
512
-
513
- }
514
-
515
- if ( ! function_exists( 'pys_get_order_total' ) ) {
516
-
517
- /**
518
- * Calculates order 'value' param depends on WooCommerce and PYS settings
519
- */
520
- function pys_get_order_total( $order ) {
521
-
522
- //wc_get_price_thousand_separator is ignored
523
- return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
524
-
525
- }
526
-
527
- }
528
-
529
- function pys_pixel_options() {
530
-
531
- $options['ajax_url'] = admin_url( 'admin-ajax.php' );
532
- $options['woo']['addtocart_enabled'] = pys_is_woocommerce_active() && pys_get_option( 'woo', 'enabled' )
533
- && (bool) pys_get_option( 'woo', 'on_add_to_cart_btn' );
534
-
535
- return $options;
536
-
537
- }
538
-
539
- add_action( 'wp_ajax_pys_woo_addtocart_params', 'pys_woo_addtocart_params_ajax_handler' );
540
- add_action( 'wp_ajax_nopriv_pys_woo_addtocart_params', 'pys_woo_addtocart_params_ajax_handler' );
541
-
542
- function pys_woo_addtocart_params_ajax_handler() {
543
-
544
- if ( empty( $_GET['product_id'] ) ) {
545
- wp_send_json_error();
546
- }
547
-
548
- $qty = empty( $_GET['quantity'] ) ? 1 : (int) $_GET['quantity'];
549
-
550
- if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $_REQUEST['variation_id'] ) ) {
551
- $product_id = (int) $_GET['variation_id'];
552
- } else {
553
- $product_id = (int) $_GET['product_id'];
554
- }
555
-
556
- $params = pys_get_woo_product_addtocart_params( $product_id, $qty );
557
- wp_send_json_success( $params );
558
-
559
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ function pys_get_woo_product_price_to_display( $product_id, $qty = 1 ) {
8
+
9
+ if ( ! $product = wc_get_product( $product_id ) ) {
10
+ return 0;
11
+ }
12
+
13
+ if ( pys_is_wc_version_gte( '2.7' ) ) {
14
+
15
+ return wc_get_price_to_display( $product, array( 'qty' => $qty ) );
16
+
17
+ } else {
18
+
19
+ return 'incl' === get_option( 'woocommerce_tax_display_shop' )
20
+ ? $product->get_price_including_tax( $qty )
21
+ : $product->get_price_excluding_tax( $qty );
22
+
23
+ }
24
+
25
+ }
26
+
27
+ if ( ! function_exists( 'pys_get_woo_product_addtocart_params' ) ) {
28
+
29
+ function pys_get_woo_product_addtocart_params( $product_id ) {
30
+
31
+ $content_id = pys_get_product_content_id( $product_id );
32
+
33
+ $params = array();
34
+ $params['content_type'] = 'product';
35
+ $params['content_ids'] = json_encode( $content_id );
36
+
37
+ // currency, value
38
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
39
+
40
+ $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
41
+ switch ( $option ) {
42
+ case 'global':
43
+ $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
44
+ break;
45
+
46
+ case 'price':
47
+ $value = pys_get_product_price( $product_id );
48
+ break;
49
+
50
+ default:
51
+ $value = null;
52
+ }
53
+
54
+ $params['value'] = $value;
55
+ $params['currency'] = get_woocommerce_currency();
56
+
57
+ }
58
+
59
+ // contents
60
+ $params['contents'] = array(
61
+ array(
62
+ 'id' => (string) reset( $content_id ),
63
+ 'quantity' => 1,
64
+ 'item_price' => pys_get_woo_product_price_to_display( $product_id ),
65
+ )
66
+ );
67
+
68
+ return $params;
69
+
70
+ }
71
+
72
+ }
73
+
74
+ if ( ! function_exists( 'pys_get_post_tags' ) ) {
75
+
76
+ /**
77
+ * Return array of product tags.
78
+ * PRO only.
79
+ */
80
+ function pys_get_post_tags( $post_id ) {
81
+
82
+ return array(); // PRO feature
83
+
84
+ }
85
+
86
+ }
87
+
88
+ if ( ! function_exists( 'pys_get_woo_code' ) ) {
89
+
90
+ /**
91
+ * Build WooCommerce related events code.
92
+ * Function adds evaluated event params to global array.
93
+ */
94
+ function pys_get_woo_code() {
95
+ global $post, $posts, $woocommerce;
96
+
97
+ // set defaults params
98
+ $params = array();
99
+ $params['content_type'] = 'product';
100
+
101
+ // ViewContent Event
102
+ if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
103
+
104
+ $product = wc_get_product( $post->ID );
105
+
106
+ $content_id = pys_get_product_content_id( $post->ID );
107
+ $params['content_ids'] = json_encode( $content_id );
108
+
109
+ if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
110
+ $params['content_type'] = 'product_group';
111
+ } else {
112
+ $params['content_type'] = 'product';
113
+ }
114
+
115
+ // @since 5.0.6
116
+ $params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
117
+ $product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
118
+
119
+ // currency, value
120
+ if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
121
+
122
+ $option = pys_get_option( 'woo', 'view_content_value_option' );
123
+ switch ( $option ) {
124
+ case 'global':
125
+ $value = pys_get_option( 'woo', 'view_content_global_value' );
126
+ break;
127
+
128
+ case 'price':
129
+ $value = pys_get_product_price( $post );
130
+ break;
131
+
132
+ default:
133
+ $value = null;
134
+ }
135
+
136
+ $params['value'] = $value;
137
+ $params['currency'] = get_woocommerce_currency();
138
+
139
+ }
140
+
141
+ // contents
142
+ $params['contents'] = json_encode( array(
143
+ array(
144
+ 'id' => (string) reset( $content_id ),
145
+ 'quantity' => 1,
146
+ 'item_price' => pys_get_woo_product_price_to_display( $post->ID ),
147
+ )
148
+ ) );
149
+
150
+ pys_add_event( 'ViewContent', $params );
151
+
152
+ return;
153
+
154
+ }
155
+
156
+ // ViewCategory
157
+ if ( pys_get_option( 'woo', 'on_view_category', true ) && is_tax( 'product_cat' ) ) {
158
+
159
+ $term = get_term_by( 'slug', get_query_var( 'term' ), 'product_cat' );
160
+ $params['content_name'] = $term->name;
161
+
162
+ $parent_ids = get_ancestors( $term->term_id, 'product_cat', 'taxonomy' );
163
+ $params['content_category'] = array();
164
+
165
+ foreach ( $parent_ids as $term_id ) {
166
+ $term = get_term_by( 'id', $term_id, 'product_cat' );
167
+ $params['content_category'][] = $term->name;
168
+ }
169
+
170
+ $params['content_category'] = implode( ',', $params['content_category'] );
171
+
172
+ $content_ids = array();
173
+ $limit = min( count( $posts ), 5 );
174
+
175
+ for ( $i = 0; $i < $limit; $i ++ ) {
176
+ $content_ids = array_merge( pys_get_product_content_id( $posts[ $i ]->ID ), $content_ids );
177
+ }
178
+
179
+ $params['content_ids'] = json_encode( $content_ids );
180
+
181
+ pys_add_event( 'ViewCategory', $params );
182
+
183
+ return;
184
+
185
+ }
186
+
187
+ // AddToCart Cart Page Event
188
+ if ( is_cart() && pys_get_option( 'woo', 'on_add_to_cart_page' ) ) {
189
+
190
+ $ids = array(); // cart items ids or sku
191
+ $contents = array();
192
+
193
+ foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
194
+
195
+ $product_id = pys_get_woo_cart_item_product_id( $item );
196
+ $content_id = pys_get_product_content_id( $product_id );
197
+ $ids = array_merge( $ids, $content_id );
198
+
199
+ // raw product id
200
+ $_product_id = empty( $item['variation_id'] ) ? $item['product_id']
201
+ : $item['variation_id'];
202
+
203
+ // contents
204
+ $contents[] = array(
205
+ 'id' => (string) reset( $content_id ),
206
+ 'quantity' => $item['quantity'],
207
+ 'item_price' => pys_get_woo_product_price_to_display( $_product_id ),
208
+ );
209
+
210
+ }
211
+
212
+ $params['content_ids'] = json_encode( $ids );
213
+ $params['contents'] = json_encode( $contents );
214
+
215
+ // currency, value
216
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
217
+
218
+ $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
219
+ switch ( $option ) {
220
+ case 'global':
221
+ $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
222
+ break;
223
+
224
+ case 'price':
225
+ $value = pys_get_cart_total();
226
+ break;
227
+
228
+ default:
229
+ $value = null;
230
+ }
231
+
232
+ $params['value'] = $value;
233
+ $params['currency'] = get_woocommerce_currency();
234
+
235
+ }
236
+
237
+ pys_add_event( 'AddToCart', $params );
238
+
239
+ return;
240
+
241
+ }
242
+
243
+ // AddToCart on Checkout page
244
+ if ( pys_get_option( 'woo', 'on_add_to_cart_checkout' ) && is_checkout() && ! is_wc_endpoint_url() ) {
245
+
246
+ $ids = array(); // cart items ids or sku
247
+ $contents = array();
248
+
249
+ foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
250
+
251
+ $product_id = pys_get_woo_cart_item_product_id( $item );
252
+ $content_id = pys_get_product_content_id( $product_id );
253
+ $ids = array_merge( $ids, $content_id );
254
+
255
+ // raw product id
256
+ $_product_id = empty( $item['variation_id'] ) ? $item['product_id']
257
+ : $item['variation_id'];
258
+
259
+ // contents
260
+ $contents[] = array(
261
+ 'id' => (string) reset( $content_id ),
262
+ 'quantity' => $item['quantity'],
263
+ 'item_price' => pys_get_woo_product_price_to_display( $_product_id ),
264
+ );
265
+
266
+ }
267
+
268
+ $params['content_ids'] = json_encode( $ids );
269
+ $params['contents'] = json_encode( $contents );
270
+
271
+ // currency, value
272
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
273
+
274
+ $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
275
+ switch ( $option ) {
276
+ case 'global':
277
+ $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
278
+ break;
279
+
280
+ case 'price':
281
+ $value = pys_get_cart_total();
282
+ break;
283
+
284
+ default:
285
+ $value = null;
286
+ }
287
+
288
+ $params['value'] = $value;
289
+ $params['currency'] = get_woocommerce_currency();
290
+
291
+ }
292
+
293
+ pys_add_event( 'AddToCart', $params );
294
+
295
+ }
296
+
297
+ // Checkout Page Event
298
+ if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
299
+
300
+ $params = pys_get_woo_checkout_params( false );
301
+
302
+ // currency, value
303
+ if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
304
+
305
+ $option = pys_get_option( 'woo', 'checkout_value_option' );
306
+ switch ( $option ) {
307
+ case 'global':
308
+ $value = pys_get_option( 'woo', 'checkout_global_value' );
309
+ break;
310
+
311
+ case 'price':
312
+ $value = pys_get_cart_total();
313
+ break;
314
+
315
+ default:
316
+ $value = null;
317
+ }
318
+
319
+ $params['value'] = $value;
320
+ $params['currency'] = get_woocommerce_currency();
321
+
322
+ }
323
+
324
+ pys_add_event( 'InitiateCheckout', $params );
325
+
326
+ return;
327
+
328
+ }
329
+
330
+ // Purchase Event
331
+ if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_order_received_page() && isset( $_REQUEST['key'] ) ) {
332
+
333
+ $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
334
+ $order = new WC_Order( $order_id );
335
+ $items = $order->get_items( 'line_item' );
336
+
337
+ $ids = array(); // order items ids or sku
338
+ $contents = array();
339
+
340
+ foreach ( $items as $item ) {
341
+
342
+ $product_id = pys_get_woo_cart_item_product_id( $item );
343
+ $content_id = pys_get_product_content_id( $product_id );
344
+ $ids = array_merge( $ids, $content_id );
345
+
346
+ // raw product id
347
+ $_product_id = empty( $item['variation_id'] ) ? $item['product_id']
348
+ : $item['variation_id'];
349
+
350
+ // contents
351
+ $contents[] = array(
352
+ 'id' => (string) reset( $content_id ),
353
+ 'quantity' => $item['quantity'],
354
+ 'item_price' => pys_get_woo_product_price_to_display( $_product_id ),
355
+ );
356
+
357
+ }
358
+
359
+ $params['content_ids'] = json_encode( $ids );
360
+ $params['contents'] = json_encode( $contents );
361
+
362
+ // currency, value
363
+ if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
364
+
365
+ $option = pys_get_option( 'woo', 'purchase_value_option' );
366
+ switch ( $option ) {
367
+ case 'global':
368
+ $value = pys_get_option( 'woo', 'purchase_global_value' );
369
+ break;
370
+
371
+ case 'total':
372
+ $value = pys_get_order_total( $order );
373
+ break;
374
+
375
+ default:
376
+ $value = null;
377
+ }
378
+
379
+ $params['value'] = $value;
380
+ $params['currency'] = get_woocommerce_currency();
381
+
382
+ }
383
+
384
+ pys_add_event( 'Purchase', $params );
385
+
386
+ return;
387
+
388
+ }
389
+
390
+ }
391
+
392
+ }
393
+
394
+ if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
395
+
396
+ /**
397
+ * Adds extra params to pixel init code. On Free always returns empty string.
398
+ * PRO only.
399
+ *
400
+ * @see: https://www.facebook.com/help/ipad-app/606443329504150
401
+ * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
402
+ * @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
403
+ *
404
+ * @return string
405
+ */
406
+ function pys_get_additional_matching_code() {
407
+
408
+ return ''; // PRO feature
409
+
410
+ }
411
+
412
+ }
413
+
414
+ if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
415
+
416
+ /**
417
+ * Adds additional post parameters like `content_name` and `category_name`.
418
+ * PRO only.
419
+ *
420
+ * @param $post WP_Post|int
421
+ * @param $params array reference to $params array
422
+ */
423
+ function pys_get_additional_woo_params( $post, &$params ) {
424
+
425
+ // PRO only
426
+
427
+ }
428
+
429
+ }
430
+
431
+ if ( ! function_exists( 'pys_general_woo_event' ) ) {
432
+
433
+ /**
434
+ * Add General event on Woo Product page. PRO only.
435
+ *
436
+ * @param $post WP_Post|int
437
+ * @param $track_tags bool
438
+ * @param $delay int
439
+ * @param $event_name string
440
+ */
441
+ function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
442
+ // PRO feature
443
+ }
444
+
445
+ }
446
+
447
+ if ( ! function_exists( 'pys_general_edd_event' ) ) {
448
+
449
+ /**
450
+ * Add General event on EDD Download page. PRO only.
451
+ *
452
+ * @param $post WP_Post|int
453
+ * @param $track_tags bool
454
+ * @param $delay int
455
+ * @param $event_name string
456
+ */
457
+ function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
458
+ // PRO feature
459
+ }
460
+
461
+ }
462
+
463
+ if ( ! function_exists( 'pys_get_product_price' ) ) {
464
+
465
+ /**
466
+ * Return product price depends on plugin, product and WooCommerce settings.
467
+ *
468
+ * @param $product_id
469
+ *
470
+ * @return null|int Product price
471
+ */
472
+ function pys_get_product_price( $product_id, $qty = 1 ) {
473
+
474
+ $product = wc_get_product( $product_id );
475
+
476
+ if ( false == $product instanceof WC_Product ) {
477
+ return 0;
478
+ }
479
+
480
+ if ( $product->is_taxable() ) {
481
+
482
+ if ( pys_is_wc_version_gte( '3.0' ) ) {
483
+ $value = wc_get_price_including_tax( $product, array( 'price' => $product->get_price(), 'qty' => $qty ) );
484
+ } else {
485
+ $value = $product->get_price_including_tax( $qty, $product->get_price() );
486
+ }
487
+
488
+ } else {
489
+
490
+ if ( pys_is_wc_version_gte( '3.0' ) ) {
491
+ $value = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_price(), 'qty' => $qty ) );
492
+ } else {
493
+ $value = $product->get_price_excluding_tax( $qty, $product->get_price() );
494
+ }
495
+
496
+ }
497
+
498
+ return $value;
499
+
500
+ }
501
+
502
+ }
503
+
504
+ if ( ! function_exists( 'pys_get_cart_total' ) ) {
505
+
506
+ function pys_get_cart_total() {
507
+ global $woocommerce;
508
+
509
+ return $woocommerce->cart->subtotal;
510
+
511
+ }
512
+
513
+ }
514
+
515
+ if ( ! function_exists( 'pys_get_order_total' ) ) {
516
+
517
+ /**
518
+ * Calculates order 'value' param depends on WooCommerce and PYS settings
519
+ */
520
+ function pys_get_order_total( $order ) {
521
+
522
+ //wc_get_price_thousand_separator is ignored
523
+ return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
524
+
525
+ }
526
+
527
+ }
528
+
529
+ function pys_pixel_options() {
530
+ global $post;
531
+
532
+ $options['woo']['addtocart_enabled'] = pys_is_woocommerce_active()
533
+ && (bool) pys_get_option( 'woo', 'enabled' )
534
+ && (bool) pys_get_option( 'woo', 'on_add_to_cart_btn' );
535
+
536
+ $options['woo']['product_data'] = pys_get_option( 'woo', 'variation_id' );
537
+
538
+ if ( is_singular( 'product' ) ) {
539
+
540
+ $options['woo']['product_id'] = $post->ID;
541
+
542
+ $options['woo']['product_value_enabled'] = (bool) pys_get_option( 'woo', 'enable_add_to_cart_value' );
543
+ $options['woo']['product_value_option'] = pys_get_option( 'woo', 'add_to_cart_value_option' );
544
+
545
+ }
546
+
547
+ return $options;
548
+
549
+ }
550
+
551
+ function pys_add_woo_loop_product_data() {
552
+ global $product;
553
+
554
+ // skip variable products, supported only on Single
555
+ if ( pys_woo_product_is_type( $product, 'variable' ) ) {
556
+ return;
557
+ }
558
+
559
+ // skip external products, not supported
560
+ if ( pys_woo_product_is_type( $product, 'external' ) ) {
561
+ return;
562
+ }
563
+
564
+ /** @var \WC_Product $product */
565
+ if ( pys_is_wc_version_gte( '2.6' ) ) {
566
+ $product_id = $product->get_id();
567
+ } else {
568
+ $product_id = $product->post->ID;
569
+ }
570
+
571
+ $params = pys_get_woo_product_addtocart_params( $product_id );
572
+ $params = json_encode( $params );
573
+
574
+ ?>
575
+
576
+ <script type="text/javascript">
577
+ /* <![CDATA[ */
578
+ window.pys_woo_product_data = window.pys_woo_product_data || [];
579
+ window.pys_woo_product_data[ <?php echo $product_id; ?> ] = <?php echo $params; ?>;
580
+ /* ]]> */
581
+ </script>
582
+
583
+ <?php
584
+
585
+ }
586
+
587
+ function pys_add_woo_single_product_data() {
588
+ global $product;
589
+
590
+ // skip external products, not supported
591
+ if ( pys_woo_product_is_type( $product, 'external' ) ) {
592
+ return;
593
+ }
594
+
595
+ /** @var \WC_Product $product */
596
+ if ( pys_is_wc_version_gte( '2.6' ) ) {
597
+ $product_id = $product->get_id();
598
+ } else {
599
+ $product_id = $product->post->ID;
600
+ }
601
+
602
+ $params[ $product_id ] = pys_get_woo_product_addtocart_params( $product_id );
603
+
604
+ if ( pys_woo_product_is_type( $product, 'variable' ) && pys_get_option( 'woo', 'add_to_cart_value_option' ) != 'main' ) {
605
+
606
+ foreach ( $product->get_available_variations() as $variation ) {
607
+
608
+ $variation = wc_get_product( $variation['variation_id'] );
609
+
610
+ if ( pys_is_wc_version_gte( '2.6' ) ) {
611
+ $variation_id = $variation->get_id();
612
+ } else {
613
+ $variation_id = $variation->post->ID;
614
+ }
615
+
616
+ $params[ $variation_id ] = pys_get_woo_product_addtocart_params( $variation_id );
617
+
618
+ }
619
+
620
+ }
621
+
622
+ ?>
623
+
624
+ <script type="text/javascript">
625
+ /* <![CDATA[ */
626
+ window.pys_woo_product_data = window.pys_woo_product_data || [];
627
+ <?php foreach ( $params as $product_id => $product_data ) : ?>
628
+ window.pys_woo_product_data[<?php echo $product_id; ?>] = <?php echo json_encode( $product_data ); ?>;
629
+ <?php endforeach; ?>
630
+ /* ]]> */
631
+ </script>
632
+
633
+ <?php
634
+ }
inc/html-admin.php CHANGED
@@ -30,7 +30,7 @@ $std_events = get_option( 'pixel_your_site_std_events' );
30
 
31
  <div class="pys-content">
32
  <form action="<?php echo admin_url('admin.php'); ?>?page=pixel-your-site" method="post">
33
- <input type="hidden" name="active_tab" value="<?php echo $pys_active_tab; ?>">
34
 
35
  <?php wp_nonce_field( 'pys_update_options' ); ?>
36
 
30
 
31
  <div class="pys-content">
32
  <form action="<?php echo admin_url('admin.php'); ?>?page=pixel-your-site" method="post">
33
+ <input type="hidden" name="active_tab" value="<?php esc_attr_e( $pys_active_tab ); ?>">
34
 
35
  <?php wp_nonce_field( 'pys_update_options' ); ?>
36
 
inc/html-tab-edd.php CHANGED
@@ -1,406 +1,406 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- ?>
8
-
9
- <div class="pys-box">
10
- <div class="pys-col pys-col-full">
11
- <h2 class="section-title"><?php _e( 'Easy Digital Downloads Settings', 'pys' ); ?></h2>
12
- <p><?php _e( 'Add all necessary events on Easy Digital Downloads with just a few clicks. On this tab you will find powerful options to customize the Facebook Pixel for your store.', 'pys' ); ?></p>
13
-
14
- <hr>
15
- <h2 class="section-title"><?php _e( 'Facebook Dynamic Product Ads Pixel Settings', 'pys' ); ?></h2>
16
- <table class="layout">
17
-
18
- <tr class="tall">
19
- <td colspan="2" class="narrow">
20
- <input type="checkbox" class="edd-events-toggle">
21
- <strong><?php _e( 'Enable Facebook Dynamic Product Ads', 'pys' ); ?></strong>
22
- <span class="help"><?php _e( 'This will automatically add ViewContent on download pages, AddToCart on add to cart button click, InitiateCheckout on checkout page and Purchase on thank you page. The events will have the required <code>content_ids</code> and <code>content_type</code> fields.', 'pys' ); ?></span>
23
- </td>
24
- </tr>
25
-
26
- <tr>
27
- <td class="alignright"><p class="label">content_ids:</p></td>
28
- <td>
29
- <select name="pys[edd][content_id]">
30
- <option <?php selected( 'id', pys_get_option( 'edd', 'content_id' ) ); ?> value="id"><?php _e( 'Download ID', 'pys' ); ?></option>
31
- <option <?php selected( 'sku', pys_get_option( 'edd', 'content_id' ) ); ?> value="sku"><?php _e( 'Download SKU', 'pys' ); ?></option>
32
- </select>
33
- </td>
34
- </tr>
35
- </table>
36
-
37
- <hr>
38
- <h2 class="section-title">PRO Options</h2>
39
- <table class="layout">
40
- <tr class="disabled" style="vertical-align: top;">
41
- <td>
42
- <h2><?php _e( 'Custom Audiences Optimization', 'pys' ); ?></h2>
43
- <input type="checkbox" disabled>
44
- <?php _e( 'Enable Additional Parameters', 'pys' ); ?>
45
- <span class="help"><?php _e( 'Download name will be pulled as <code>content_name</code>, and Download Category as <code>category_name</code> for all EDD events.', 'pys' ); ?></span>
46
- <span class="help" style="margin-bottom: 20px;"><?php _e( 'The number of items is <code>num_items</code> for InitiateCheckout and Purchase events.', 'pys' ); ?></span>
47
- <input type="checkbox" disabled>
48
- <?php _e( 'Track tags', 'pys' ); ?>
49
- <span class="help"><?php _e( 'Will pull <code>tags</code> param on all EDD events.', 'pys' );
50
- ?></span>
51
- </td>
52
-
53
- <td>
54
- <h2><?php _e( 'Tax Options', 'pys' ); ?></h2>
55
- <?php _e( 'Value:', 'pys' ); ?> &nbsp;&nbsp;
56
- <select disabled>
57
- <option selected>Includes Tax</option>
58
- </select>
59
- </td>
60
- </tr>
61
-
62
- <tr style="vertical-align: top;">
63
- <td>
64
- <p><?php _e( '<strong>Important for Custom Audiences.</strong> Use this together with the General Event option.', 'pys' ); ?></p>
65
- <p><?php _e( 'Learn how to <strong>Create Powerful Custom Audiences</strong> based on Events: <strong><a href="http://www.pixelyoursite.com/use-general-event-existing-clients" target="_blank">Click to Download Your Free Guide</a></strong>', 'pys' ); ?></p>
66
-
67
- </td>
68
- <td>
69
- <p><strong>Unlock all the PRO features: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin"
70
- target="_blank">Upgrade NOW</a></strong></p>
71
- </td>
72
- </tr>
73
- </table>
74
-
75
- <!-- ViewContent -->
76
- <hr>
77
- <h2 class="section-title"><?php _e( 'ViewContent Event', 'pys' ); ?></h2>
78
- <p><?php _e( 'ViewContent is added on Download Pages and it is required for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
79
- <table class="layout">
80
-
81
- <tr class="tall">
82
- <td colspan="2" class="narrow">
83
- <?php pys_checkbox( 'edd', 'on_view_content', 'edd-option' ); ?>
84
- <strong><?php _e( 'Enable ViewContent on Download Pages', 'pys' ); ?></strong>
85
- </td>
86
- </tr>
87
-
88
- <tr>
89
- <td class="alignright disabled"><p class="label"><?php _e( 'Delay', 'pys' ); ?></p></td>
90
- <td>
91
- <input type="number" disabled>
92
- <?php _e( 'seconds', 'pys' ); ?> - <strong>This is a PRO feature</strong> - <a
93
- href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
94
- </td>
95
- </tr>
96
-
97
- <tr>
98
- <td></td>
99
- <td>
100
- <?php pys_checkbox( 'edd', 'enable_view_content_value' ); ?>
101
- <?php _e( 'Enable Value', 'pys' ); ?>
102
- <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
103
- </td>
104
- </tr>
105
-
106
- <tr>
107
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
108
- <td></td>
109
- </tr>
110
-
111
- <tr class="disabled">
112
- <td class="alignright"><p class="label"><?php _e( 'Download price', 'pys' ); ?></p></td>
113
- <td>
114
- <input type="radio">
115
- </td>
116
- </tr>
117
-
118
- <tr class="disabled">
119
- <td class="alignright"><p class="label"><?php _e( 'Percent of download price', 'pys' ); ?></p></td>
120
- <td>
121
- <input type="radio">
122
- <input type="text">&nbsp;%
123
- </td>
124
- </tr>
125
-
126
- <tr>
127
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
128
- <td>
129
- <input type="radio" checked>
130
- <?php pys_text_field( 'edd', 'view_content_global_value' ); ?>
131
- </td>
132
- </tr>
133
-
134
- <tr>
135
- <td></td>
136
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to <strong>enable all value options</strong></td>
137
- </tr>
138
-
139
- </table>
140
-
141
- <hr>
142
- <h2 class="section-title">ViewCategory Event</h2>
143
- <p>ViewCategory is added on download categories and it is required for Facebook Dynamic Product Ads.</p>
144
- <table class="layout">
145
- <tr class="">
146
- <td colspan="2" class="narrow">
147
- <input type="checkbox" name="pys[edd][on_view_category]" value="1" class="edd-option"
148
- <?php pys_checkbox_state( 'edd', 'on_view_category' ); ?> >
149
- <strong>Enable ViewCategory on download categories</strong>
150
- </td>
151
- </tr>
152
- </table>
153
-
154
- <!-- AddToCart -->
155
- <hr>
156
- <h2 class="section-title"><?php _e( 'AddToCart Event', 'pys' ); ?></h2>
157
- <p><?php _e( 'AddToCart event will be added on add to cart button click and on cart page. It is required for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
158
- <table class="layout">
159
-
160
- <tr>
161
- <td colspan="2" class="narrow">
162
- <?php pys_checkbox( 'edd', 'on_add_to_cart_btn', 'edd-option' ); ?>
163
- <strong><?php _e( 'Enable AddToCart on add to cart button', 'pys' ); ?></strong>
164
- </td>
165
- </tr>
166
-
167
- <tr class="tall">
168
- <td colspan="2" class="narrow">
169
- <?php pys_checkbox( 'edd', 'on_add_to_cart_checkout', 'edd-option' ); ?>
170
- <strong>Enable AddToCart on checkout page</strong>
171
- </td>
172
- </tr>
173
-
174
- <tr>
175
- <td></td>
176
- <td>
177
- <?php pys_checkbox( 'edd', 'enable_add_to_cart_value' ); ?>
178
- <?php _e( 'Enable Value', 'pys' ); ?>
179
- <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
180
- </td>
181
- </tr>
182
-
183
- <tr>
184
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
185
- <td></td>
186
- </tr>
187
-
188
- <tr class="disabled">
189
- <td class="alignright"><p class="label"><?php _e( 'Downloads price (subtotal)', 'pys' ); ?></p></td>
190
- <td>
191
- <input type="radio">
192
- </td>
193
- </tr>
194
-
195
- <tr class="disabled">
196
- <td class="alignright"><p class="label"><?php _e( 'Percent of downloads value (subtotal)', 'pys' ); ?></p></td>
197
- <td>
198
- <input type="radio">
199
- <input type="text">&nbsp;%
200
- </td>
201
- </tr>
202
-
203
- <tr>
204
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
205
- <td>
206
- <input type="radio" checked>
207
- <?php pys_text_field( 'edd', 'add_to_cart_global_value' ); ?>
208
- </td>
209
- </tr>
210
-
211
- <tr>
212
- <td></td>
213
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
214
- <strong>enable all value options</strong></td>
215
- </tr>
216
-
217
- </table>
218
-
219
- <!-- InitiateCheckout -->
220
- <hr>
221
- <h2 class="section-title"><?php _e( 'InitiateCheckout Event', 'pys' ); ?></h2>
222
- <p><?php _e( 'InitiateCheckout event will be enabled on the Checkout page. It is not mandatory for Facebook Dynamic Product Ads, but it is better to keep it on.', 'pys' ); ?></p>
223
- <table class="layout">
224
-
225
- <tr class="tall">
226
- <td colspan="2" class="narrow">
227
- <?php pys_checkbox( 'edd', 'on_checkout_page', 'edd-option' ); ?>
228
- <strong><?php _e( 'Enable InitiateCheckout on Checkout page', 'pys' ); ?></strong>
229
- </td>
230
- </tr>
231
-
232
- <tr>
233
- <td></td>
234
- <td>
235
- <?php pys_checkbox( 'edd', 'enable_checkout_value' ); ?>
236
- <?php _e( 'Enable Value', 'pys' ); ?>
237
- <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
238
- </td>
239
- </tr>
240
-
241
- <tr>
242
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
243
- <td></td>
244
- </tr>
245
-
246
- <tr class="disabled">
247
- <td class="alignright"><p class="label"><?php _e( 'Downloads price (subtotal)', 'pys' ); ?></p></td>
248
- <td>
249
- <input type="radio">
250
- </td>
251
- </tr>
252
-
253
- <tr class="disabled">
254
- <td class="alignright"><p
255
- class="label"><?php _e( 'Percent of downloads value (subtotal)', 'pys' ); ?></p></td>
256
- <td>
257
- <input type="radio">
258
- <input type="text">&nbsp;%
259
- </td>
260
- </tr>
261
-
262
- <tr>
263
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
264
- <td>
265
- <input type="radio" checked>
266
- <?php pys_text_field( 'edd', 'checkout_global_value' ); ?>
267
- </td>
268
- </tr>
269
-
270
- <tr>
271
- <td></td>
272
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
273
- <strong>enable all value options</strong></td>
274
- </tr>
275
-
276
- </table>
277
-
278
- <!-- Purchase -->
279
- <hr>
280
- <h2 class="section-title"><?php _e( 'Purchase Event', 'pys' ); ?></h2>
281
- <p><?php _e( 'Purchase event will be enabled on the Success Page. It is mandatory for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
282
- <table class="layout">
283
-
284
- <tr class="tall">
285
- <td colspan="2" class="narrow">
286
- <?php pys_checkbox( 'edd', 'on_success_page', 'edd-option' ); ?>
287
- <strong><?php _e( 'Enable Purchase event on Success Page', 'pys' ); ?></strong>
288
- </td>
289
- </tr>
290
-
291
- <tr>
292
- <td></td>
293
- <td>
294
- <?php pys_checkbox( 'edd', 'enable_purchase_value' ); ?>
295
- <?php _e( 'Enable Value', 'pys' ); ?>
296
- <span class="help"><?php _e( 'Add value and currency - <strong>Very important for ROI
297
- measurement</strong>', 'pys' ); ?></span>
298
- </td>
299
- </tr>
300
-
301
- <tr>
302
- <td class="alignright disabled">
303
- <p class="label"><?php _e( 'Fire the event on transaction only', 'pys' ); ?></p>
304
- </td>
305
- <td>
306
- <select disabled>
307
- <option><?php _e( 'Off', 'pys' ); ?></option>
308
- </select> - <strong>This is a PRO feature</strong> - <a
309
- href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
310
- <span class="help"><?php _e( 'This will avoid the Purchase event to be fired when the success page is visited but no transaction has occurred. <b>It will improve conversion tracking.</b>', 'pys' ); ?></span>
311
- </td>
312
- </tr>
313
-
314
- <tr>
315
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
316
- <td></td>
317
- </tr>
318
-
319
- <tr class="disabled">
320
- <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
321
- <td>
322
- <input type="radio">
323
- </td>
324
- </tr>
325
-
326
- <tr class="disabled">
327
- <td class="alignright"><p class="label"><?php _e( 'Percent of Total', 'pys' ); ?></p></td>
328
- <td>
329
- <input type="radio">
330
- <input type="text">&nbsp;%
331
- </td>
332
- </tr>
333
-
334
- <tr>
335
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
336
- <td>
337
- <input type="radio" checked>
338
- <?php pys_text_field( 'edd', 'purchase_global_value' ); ?>
339
- </td>
340
- </tr>
341
-
342
- <tr class="tall">
343
- <td></td>
344
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
345
- <strong>enable all value options</strong></td>
346
- </tr>
347
-
348
- <tr>
349
- <td class="alignright">
350
- <p class="label big"><?php _e( 'Custom Audience Optimization:', 'pys' ); ?></p>
351
- </td>
352
- <td>
353
- <span class="help"><strong>This is a PRO feature</strong> - <a
354
- href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
355
- </td>
356
- </tr>
357
-
358
- <tr class="disabled">
359
- <td></td>
360
- <td>
361
- <input type="checkbox">
362
- <strong><?php _e( 'Add Town, State and Country parameters', 'pys' ); ?></strong>
363
- <span
364
- class="help"><?php _e( 'Will pull <code>town</code>, <code>state</code> and <code>country</code>', 'pys' ); ?></span>
365
- </td>
366
- </tr>
367
-
368
- <tr class="disabled">
369
- <td></td>
370
- <td>
371
- <input type="checkbox">
372
- <strong><?php _e( 'Add Payment Method parameter', 'pys' ); ?></strong>
373
- <span class="help"><?php _e( 'Will pull <code>payment</code>', 'pys' ); ?></span>
374
- </td>
375
- </tr>
376
-
377
- <tr class="disabled">
378
- <td></td>
379
- <td>
380
- <input type="checkbox">
381
- <strong><?php _e( 'Add Coupons parameter', 'pys' ); ?></strong>
382
- <span class="help"><?php _e( 'Will pull <code>coupon_used</code> and <code>coupon_name</code>', 'pys' ); ?></span>
383
- </td>
384
- </tr>
385
-
386
- </table>
387
-
388
- <p><?php _e( '<strong>Important:</strong> For the Purchase Event to work, the client must be redirected on the EDD Success Page after payment.', 'pys' ); ?></p>
389
-
390
- <!-- Activate EDD -->
391
- <hr>
392
- <table class="layout">
393
- <tr>
394
- <td class="alignright">
395
- <p class="label big"><?php _e( 'Activate Easy Digital Downloads Pixel Settings', 'pys' ); ?></p>
396
- </td>
397
- <td>
398
- <?php pys_checkbox( 'edd', 'enabled' ); ?>
399
- </td>
400
- </tr>
401
- </table>
402
-
403
- <button class="pys-btn pys-btn-blue pys-btn-big aligncenter"><?php _e( 'Save Settings', 'pys' ); ?></button>
404
-
405
- </div>
406
  </div>
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ ?>
8
+
9
+ <div class="pys-box">
10
+ <div class="pys-col pys-col-full">
11
+ <h2 class="section-title"><?php _e( 'Easy Digital Downloads Settings', 'pys' ); ?></h2>
12
+ <p><?php _e( 'Add all necessary events on Easy Digital Downloads with just a few clicks. On this tab you will find powerful options to customize the Facebook Pixel for your store.', 'pys' ); ?></p>
13
+
14
+ <hr>
15
+ <h2 class="section-title"><?php _e( 'Facebook Dynamic Product Ads Pixel Settings', 'pys' ); ?></h2>
16
+ <table class="layout">
17
+
18
+ <tr class="tall">
19
+ <td colspan="2" class="narrow">
20
+ <input type="checkbox" class="edd-events-toggle">
21
+ <strong><?php _e( 'Enable Facebook Dynamic Product Ads', 'pys' ); ?></strong>
22
+ <span class="help"><?php _e( 'This will automatically add ViewContent on download pages, AddToCart on add to cart button click, InitiateCheckout on checkout page and Purchase on thank you page. The events will have the required <code>content_ids</code> and <code>content_type</code> fields.', 'pys' ); ?></span>
23
+ </td>
24
+ </tr>
25
+
26
+ <tr>
27
+ <td class="alignright"><p class="label">content_ids:</p></td>
28
+ <td>
29
+ <select name="pys[edd][content_id]">
30
+ <option <?php selected( 'id', pys_get_option( 'edd', 'content_id' ) ); ?> value="id"><?php _e( 'Download ID', 'pys' ); ?></option>
31
+ <option <?php selected( 'sku', pys_get_option( 'edd', 'content_id' ) ); ?> value="sku"><?php _e( 'Download SKU', 'pys' ); ?></option>
32
+ </select>
33
+ </td>
34
+ </tr>
35
+ </table>
36
+
37
+ <hr>
38
+ <h2 class="section-title">PRO Options</h2>
39
+ <table class="layout">
40
+ <tr class="disabled" style="vertical-align: top;">
41
+ <td>
42
+ <h2><?php _e( 'Custom Audiences Optimization', 'pys' ); ?></h2>
43
+ <input type="checkbox" disabled>
44
+ <?php _e( 'Enable Additional Parameters', 'pys' ); ?>
45
+ <span class="help"><?php _e( 'Download name will be pulled as <code>content_name</code>, and Download Category as <code>category_name</code> for all EDD events.', 'pys' ); ?></span>
46
+ <span class="help" style="margin-bottom: 20px;"><?php _e( 'The number of items is <code>num_items</code> for InitiateCheckout and Purchase events.', 'pys' ); ?></span>
47
+ <input type="checkbox" disabled>
48
+ <?php _e( 'Track tags', 'pys' ); ?>
49
+ <span class="help"><?php _e( 'Will pull <code>tags</code> param on all EDD events.', 'pys' );
50
+ ?></span>
51
+ </td>
52
+
53
+ <td>
54
+ <h2><?php _e( 'Tax Options', 'pys' ); ?></h2>
55
+ <?php _e( 'Value:', 'pys' ); ?> &nbsp;&nbsp;
56
+ <select disabled>
57
+ <option selected>Includes Tax</option>
58
+ </select>
59
+ </td>
60
+ </tr>
61
+
62
+ <tr style="vertical-align: top;">
63
+ <td>
64
+ <p><?php _e( '<strong>Important for Custom Audiences.</strong> Use this together with the General Event option.', 'pys' ); ?></p>
65
+ <p><?php _e( 'Learn how to <strong>Create Powerful Custom Audiences</strong> based on Events: <strong><a href="http://www.pixelyoursite.com/use-general-event-existing-clients" target="_blank">Click to Download Your Free Guide</a></strong>', 'pys' ); ?></p>
66
+
67
+ </td>
68
+ <td>
69
+ <p><strong>Unlock all the PRO features: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin"
70
+ target="_blank">Upgrade NOW</a></strong></p>
71
+ </td>
72
+ </tr>
73
+ </table>
74
+
75
+ <!-- ViewContent -->
76
+ <hr>
77
+ <h2 class="section-title"><?php _e( 'ViewContent Event', 'pys' ); ?></h2>
78
+ <p><?php _e( 'ViewContent is added on Download Pages and it is required for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
79
+ <table class="layout">
80
+
81
+ <tr class="tall">
82
+ <td colspan="2" class="narrow">
83
+ <?php pys_checkbox( 'edd', 'on_view_content', 'edd-option' ); ?>
84
+ <strong><?php _e( 'Enable ViewContent on Download Pages', 'pys' ); ?></strong>
85
+ </td>
86
+ </tr>
87
+
88
+ <tr>
89
+ <td class="alignright disabled"><p class="label"><?php _e( 'Delay', 'pys' ); ?></p></td>
90
+ <td>
91
+ <input type="number" disabled>
92
+ <?php _e( 'seconds', 'pys' ); ?> - <strong>This is a PRO feature</strong> - <a
93
+ href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
94
+ </td>
95
+ </tr>
96
+
97
+ <tr>
98
+ <td></td>
99
+ <td>
100
+ <?php pys_checkbox( 'edd', 'enable_view_content_value' ); ?>
101
+ <?php _e( 'Enable Value', 'pys' ); ?>
102
+ <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
103
+ </td>
104
+ </tr>
105
+
106
+ <tr>
107
+ <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
108
+ <td></td>
109
+ </tr>
110
+
111
+ <tr class="disabled">
112
+ <td class="alignright"><p class="label"><?php _e( 'Download price', 'pys' ); ?></p></td>
113
+ <td>
114
+ <input type="radio">
115
+ </td>
116
+ </tr>
117
+
118
+ <tr class="disabled">
119
+ <td class="alignright"><p class="label"><?php _e( 'Percent of download price', 'pys' ); ?></p></td>
120
+ <td>
121
+ <input type="radio">
122
+ <input type="text">&nbsp;%
123
+ </td>
124
+ </tr>
125
+
126
+ <tr>
127
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
128
+ <td>
129
+ <input type="radio" checked>
130
+ <?php pys_text_field( 'edd', 'view_content_global_value' ); ?>
131
+ </td>
132
+ </tr>
133
+
134
+ <tr>
135
+ <td></td>
136
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to <strong>enable all value options</strong></td>
137
+ </tr>
138
+
139
+ </table>
140
+
141
+ <hr>
142
+ <h2 class="section-title">ViewCategory Event</h2>
143
+ <p>ViewCategory is added on download categories and it is required for Facebook Dynamic Product Ads.</p>
144
+ <table class="layout">
145
+ <tr class="">
146
+ <td colspan="2" class="narrow">
147
+ <input type="checkbox" name="pys[edd][on_view_category]" value="1" class="edd-option"
148
+ <?php pys_checkbox_state( 'edd', 'on_view_category' ); ?> >
149
+ <strong>Enable ViewCategory on download categories</strong>
150
+ </td>
151
+ </tr>
152
+ </table>
153
+
154
+ <!-- AddToCart -->
155
+ <hr>
156
+ <h2 class="section-title"><?php _e( 'AddToCart Event', 'pys' ); ?></h2>
157
+ <p><?php _e( 'AddToCart event will be added on add to cart button click and on cart page. It is required for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
158
+ <table class="layout">
159
+
160
+ <tr>
161
+ <td colspan="2" class="narrow">
162
+ <?php pys_checkbox( 'edd', 'on_add_to_cart_btn', 'edd-option' ); ?>
163
+ <strong><?php _e( 'Enable AddToCart on add to cart button', 'pys' ); ?></strong>
164
+ </td>
165
+ </tr>
166
+
167
+ <tr class="tall">
168
+ <td colspan="2" class="narrow">
169
+ <?php pys_checkbox( 'edd', 'on_add_to_cart_checkout', 'edd-option' ); ?>
170
+ <strong>Enable AddToCart on checkout page</strong>
171
+ </td>
172
+ </tr>
173
+
174
+ <tr>
175
+ <td></td>
176
+ <td>
177
+ <?php pys_checkbox( 'edd', 'enable_add_to_cart_value' ); ?>
178
+ <?php _e( 'Enable Value', 'pys' ); ?>
179
+ <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
180
+ </td>
181
+ </tr>
182
+
183
+ <tr>
184
+ <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
185
+ <td></td>
186
+ </tr>
187
+
188
+ <tr class="disabled">
189
+ <td class="alignright"><p class="label"><?php _e( 'Downloads price (subtotal)', 'pys' ); ?></p></td>
190
+ <td>
191
+ <input type="radio">
192
+ </td>
193
+ </tr>
194
+
195
+ <tr class="disabled">
196
+ <td class="alignright"><p class="label"><?php _e( 'Percent of downloads value (subtotal)', 'pys' ); ?></p></td>
197
+ <td>
198
+ <input type="radio">
199
+ <input type="text">&nbsp;%
200
+ </td>
201
+ </tr>
202
+
203
+ <tr>
204
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
205
+ <td>
206
+ <input type="radio" checked>
207
+ <?php pys_text_field( 'edd', 'add_to_cart_global_value' ); ?>
208
+ </td>
209
+ </tr>
210
+
211
+ <tr>
212
+ <td></td>
213
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
214
+ <strong>enable all value options</strong></td>
215
+ </tr>
216
+
217
+ </table>
218
+
219
+ <!-- InitiateCheckout -->
220
+ <hr>
221
+ <h2 class="section-title"><?php _e( 'InitiateCheckout Event', 'pys' ); ?></h2>
222
+ <p><?php _e( 'InitiateCheckout event will be enabled on the Checkout page. It is not mandatory for Facebook Dynamic Product Ads, but it is better to keep it on.', 'pys' ); ?></p>
223
+ <table class="layout">
224
+
225
+ <tr class="tall">
226
+ <td colspan="2" class="narrow">
227
+ <?php pys_checkbox( 'edd', 'on_checkout_page', 'edd-option' ); ?>
228
+ <strong><?php _e( 'Enable InitiateCheckout on Checkout page', 'pys' ); ?></strong>
229
+ </td>
230
+ </tr>
231
+
232
+ <tr>
233
+ <td></td>
234
+ <td>
235
+ <?php pys_checkbox( 'edd', 'enable_checkout_value' ); ?>
236
+ <?php _e( 'Enable Value', 'pys' ); ?>
237
+ <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
238
+ </td>
239
+ </tr>
240
+
241
+ <tr>
242
+ <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
243
+ <td></td>
244
+ </tr>
245
+
246
+ <tr class="disabled">
247
+ <td class="alignright"><p class="label"><?php _e( 'Downloads price (subtotal)', 'pys' ); ?></p></td>
248
+ <td>
249
+ <input type="radio">
250
+ </td>
251
+ </tr>
252
+
253
+ <tr class="disabled">
254
+ <td class="alignright"><p
255
+ class="label"><?php _e( 'Percent of downloads value (subtotal)', 'pys' ); ?></p></td>
256
+ <td>
257
+ <input type="radio">
258
+ <input type="text">&nbsp;%
259
+ </td>
260
+ </tr>
261
+
262
+ <tr>
263
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
264
+ <td>
265
+ <input type="radio" checked>
266
+ <?php pys_text_field( 'edd', 'checkout_global_value' ); ?>
267
+ </td>
268
+ </tr>
269
+
270
+ <tr>
271
+ <td></td>
272
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
273
+ <strong>enable all value options</strong></td>
274
+ </tr>
275
+
276
+ </table>
277
+
278
+ <!-- Purchase -->
279
+ <hr>
280
+ <h2 class="section-title"><?php _e( 'Purchase Event', 'pys' ); ?></h2>
281
+ <p><?php _e( 'Purchase event will be enabled on the Success Page. It is mandatory for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
282
+ <table class="layout">
283
+
284
+ <tr class="tall">
285
+ <td colspan="2" class="narrow">
286
+ <?php pys_checkbox( 'edd', 'on_success_page', 'edd-option' ); ?>
287
+ <strong><?php _e( 'Enable Purchase event on Success Page', 'pys' ); ?></strong>
288
+ </td>
289
+ </tr>
290
+
291
+ <tr>
292
+ <td></td>
293
+ <td>
294
+ <?php pys_checkbox( 'edd', 'enable_purchase_value' ); ?>
295
+ <?php _e( 'Enable Value', 'pys' ); ?>
296
+ <span class="help"><?php _e( 'Add value and currency - <strong>Very important for ROI
297
+ measurement</strong>', 'pys' ); ?></span>
298
+ </td>
299
+ </tr>
300
+
301
+ <tr>
302
+ <td class="alignright disabled">
303
+ <p class="label"><?php _e( 'Fire the event on transaction only', 'pys' ); ?></p>
304
+ </td>
305
+ <td>
306
+ <select disabled>
307
+ <option><?php _e( 'Off', 'pys' ); ?></option>
308
+ </select> - <strong>This is a PRO feature</strong> - <a
309
+ href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
310
+ <span class="help"><?php _e( 'This will avoid the Purchase event to be fired when the success page is visited but no transaction has occurred. <b>It will improve conversion tracking.</b>', 'pys' ); ?></span>
311
+ </td>
312
+ </tr>
313
+
314
+ <tr>
315
+ <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
316
+ <td></td>
317
+ </tr>
318
+
319
+ <tr class="disabled">
320
+ <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
321
+ <td>
322
+ <input type="radio">
323
+ </td>
324
+ </tr>
325
+
326
+ <tr class="disabled">
327
+ <td class="alignright"><p class="label"><?php _e( 'Percent of Total', 'pys' ); ?></p></td>
328
+ <td>
329
+ <input type="radio">
330
+ <input type="text">&nbsp;%
331
+ </td>
332
+ </tr>
333
+
334
+ <tr>
335
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
336
+ <td>
337
+ <input type="radio" checked>
338
+ <?php pys_text_field( 'edd', 'purchase_global_value' ); ?>
339
+ </td>
340
+ </tr>
341
+
342
+ <tr class="tall">
343
+ <td></td>
344
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
345
+ <strong>enable all value options</strong></td>
346
+ </tr>
347
+
348
+ <tr>
349
+ <td class="alignright">
350
+ <p class="label big"><?php _e( 'Custom Audience Optimization:', 'pys' ); ?></p>
351
+ </td>
352
+ <td>
353
+ <span class="help"><strong>This is a PRO feature</strong> - <a
354
+ href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
355
+ </td>
356
+ </tr>
357
+
358
+ <tr class="disabled">
359
+ <td></td>
360
+ <td>
361
+ <input type="checkbox">
362
+ <strong><?php _e( 'Add Town, State and Country parameters', 'pys' ); ?></strong>
363
+ <span
364
+ class="help"><?php _e( 'Will pull <code>town</code>, <code>state</code> and <code>country</code>', 'pys' ); ?></span>
365
+ </td>
366
+ </tr>
367
+
368
+ <tr class="disabled">
369
+ <td></td>
370
+ <td>
371
+ <input type="checkbox">
372
+ <strong><?php _e( 'Add Payment Method parameter', 'pys' ); ?></strong>
373
+ <span class="help"><?php _e( 'Will pull <code>payment</code>', 'pys' ); ?></span>
374
+ </td>
375
+ </tr>
376
+
377
+ <tr class="disabled">
378
+ <td></td>
379
+ <td>
380
+ <input type="checkbox">
381
+ <strong><?php _e( 'Add Coupons parameter', 'pys' ); ?></strong>
382
+ <span class="help"><?php _e( 'Will pull <code>coupon_used</code> and <code>coupon_name</code>', 'pys' ); ?></span>
383
+ </td>
384
+ </tr>
385
+
386
+ </table>
387
+
388
+ <p><?php _e( '<strong>Important:</strong> For the Purchase Event to work, the client must be redirected on the EDD Success Page after payment.', 'pys' ); ?></p>
389
+
390
+ <!-- Activate EDD -->
391
+ <hr>
392
+ <table class="layout">
393
+ <tr>
394
+ <td class="alignright">
395
+ <p class="label big"><?php _e( 'Activate Easy Digital Downloads Pixel Settings', 'pys' ); ?></p>
396
+ </td>
397
+ <td>
398
+ <?php pys_checkbox( 'edd', 'enabled' ); ?>
399
+ </td>
400
+ </tr>
401
+ </table>
402
+
403
+ <button class="pys-btn pys-btn-blue pys-btn-big aligncenter"><?php _e( 'Save Settings', 'pys' ); ?></button>
404
+
405
+ </div>
406
  </div>
inc/html-tab-woo-general.php CHANGED
@@ -1,591 +1,581 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- ?>
8
-
9
- <div class="pys-box">
10
- <div class="pys-col pys-col-full">
11
- <h2 class="section-title">WooCommerce Pixel Settings</h2>
12
- <p>Add all necessary events on WooCommerce with just a few clicks. On this tab you will find powerful options to customize the Facebook Pixel for your store.</p>
13
-
14
- <hr>
15
- <h2 class="section-title">Facebook Dynamic Product Ads Pixel Settings</h2>
16
- <table class="layout" id="woo_content_id">
17
- <tr class="tall">
18
- <td colspan="2" class="narrow">
19
- <input type="checkbox" class="woo-events-toggle"><strong>Enable Facebook Dynamic Product Ads</strong>
20
- <span class="help">This will automatically add ViewContent on product pages, AddToCart on add to cart button click and cart page, InitiateCheckout on checkout page and Purchase on thank you page. The events will have the required <code>content_ids</code> and <code>content_type</code> parameters.</span>
21
- </td>
22
- </tr>
23
-
24
- <?php do_action( 'pys_fb_pixel_admin_woo_content_id_before' ); ?>
25
-
26
- <tr class="content_id">
27
- <td></td>
28
- <td>
29
- <?php pys_checkbox( 'woo', 'variation_id', null, 'main' ); ?>
30
- <?php _e( 'Treat variable products like simple products', 'pys' ); ?>
31
-
32
- <span class="help">Turn this option ON when your Product Catalog doesn't include the variants for variable products.</span>
33
- </td>
34
- </tr>
35
-
36
- <tr class="content_id">
37
- <td class="alignright"><p class="label">content_ids:</p></td>
38
- <td>
39
- <select name="pys[woo][content_id]">
40
- <option <?php selected( 'id', pys_get_option( 'woo', 'content_id' ) ); ?> value="id">Product ID
41
- </option>
42
- <option <?php selected( 'sku', pys_get_option( 'woo', 'content_id' ) ); ?> value="sku">Product SKU
43
- </option>
44
- </select>
45
- </td>
46
- </tr>
47
-
48
- <tr>
49
- <td></td>
50
- <td>
51
- <p><strong>Product Catalog Feed</strong> - use our dedicated plugin to create 100% Dynamic Ads compatible feeds with just a few clicks:</p>
52
- <p><a href="http://www.pixelyoursite.com/product-catalog-facebook" target="_blank">Download Product Catalog Feed Plugin for a big discount</a></p>
53
- </td>
54
- </tr>
55
- </table>
56
-
57
- <hr>
58
- <h2 class="section-title">PRO Options</h2>
59
- <table class="layout">
60
- <tr class="disabled" style="vertical-align: top;">
61
- <td>
62
-
63
- <h2>Custom Audiences Optimization</h2>
64
-
65
- <input type="checkbox" disabled>Enable Additional Parameters
66
- <span class="help">Product name will be pulled as <code>content_name</code>, and Product Category as <code>category_name</code> for all WooCommerce events.</span>
67
- <span class="help" style="margin-bottom: 20px;">The number of items is <code>num_items</code> for InitiateCheckout and Purchase events.</span>
68
-
69
- <input type="checkbox" disabled>Track tags
70
- <span class="help">Will pull <code>tags</code> param on all WooCommerce events.</span>
71
-
72
-
73
- </td>
74
- <td>
75
-
76
- <h2>Tax Options</h2>
77
- Value: &nbsp;&nbsp;
78
- <select>
79
- <option selected>Includes Tax</option>
80
- </select>
81
-
82
- </td>
83
- </tr>
84
-
85
- <tr style="vertical-align: top;">
86
- <td>
87
-
88
- <p><strong>Important for Custom Audiences.</strong> Use this together with the General Event option.</p>
89
- <p>Learn how to <strong>Create Powerful Custom Audiences</strong> based on Events: <strong><a href="http://www.pixelyoursite.com/general-event" target="_blank">Click to Download Your Free Guide</a></strong></p>
90
- </td>
91
- <td>
92
-
93
- <p><strong>Unlock all the PRO features: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank">Upgrade NOW</a></strong></p>
94
- </td>
95
- </tr>
96
-
97
-
98
- </table>
99
-
100
- <hr>
101
- <h2 class="section-title">ViewContent Event</h2>
102
- <p>ViewContent is added on Product Pages and it is required for Facebook Dynamic Product Ads.</p>
103
- <table class="layout">
104
- <tr class="tall">
105
- <td colspan="2" class="narrow">
106
- <input type="checkbox" name="pys[woo][on_view_content]" value="1" class="woo-option"
107
- <?php pys_checkbox_state( 'woo', 'on_view_content' ); ?> >
108
- <strong>Enable ViewContent on Product Pages</strong>
109
- </td>
110
- </tr>
111
-
112
- <tr>
113
- <td class="alignright disabled"><p class="label">Delay</p></td>
114
- <td>
115
- <input type="number" disabled> seconds - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
116
- <span class="help">Avoid retargeting bouncing users (It is better to add a lower time that the desired one because the pixel code will not load instantaneously). People that spent less time on the page will not be part of your Custom Audiences. You will not spend money retargeting them and your Lookalike Audiences will be more accurate.</span>
117
- </td>
118
- </tr>
119
-
120
- <tr>
121
- <td></td>
122
- <td>
123
- <?php pys_checkbox( 'woo', 'enable_view_content_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
124
- <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
125
- </td>
126
- </tr>
127
-
128
- <tr>
129
- <td class="alignright"><p class="label big">Define value:</p></td>
130
- <td></td>
131
- </tr>
132
-
133
- <tr>
134
- <td class="alignright"><p class="label"><?php _e( 'Product price', 'pys' ); ?></p></td>
135
- <td>
136
- <input type="radio" name="pys[woo][view_content_value_option]" value="price"
137
- <?php echo pys_radio_state( 'woo', 'view_content_value_option', 'price' ); ?> >
138
- </td>
139
- </tr>
140
-
141
- <tr class="disabled">
142
- <td class="alignright"><p class="label">Percent of product price</p></td>
143
- <td>
144
- <input type="radio">
145
- <input type="text">%
146
- </td>
147
- </tr>
148
-
149
- <tr>
150
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
151
- <td>
152
- <input type="radio" name="pys[woo][view_content_value_option]" value="global"
153
- <?php echo pys_radio_state( 'woo', 'view_content_value_option', 'global' ); ?> >
154
- <input type="text" name="pys[woo][view_content_global_value]" value="<?php echo pys_get_option( 'woo', 'view_content_global_value' ); ?>">
155
- </td>
156
- </tr>
157
-
158
- <tr>
159
- <td></td>
160
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
161
- <strong>enable all value options</strong></td>
162
- </tr>
163
-
164
- </table>
165
-
166
- <hr>
167
- <h2 class="section-title">ViewCategory Event</h2>
168
- <p>ViewCategory is added on product categories and it is required for Facebook Dynamic Product Ads.</p>
169
- <table class="layout">
170
- <tr class="">
171
- <td colspan="2" class="narrow">
172
- <input type="checkbox" name="pys[woo][on_view_category]" value="1" class="woo-option"
173
- <?php pys_checkbox_state( 'woo', 'on_view_category' ); ?> >
174
- <strong>Enable ViewCategory on product categories</strong>
175
- </td>
176
- </tr>
177
- </table>
178
-
179
- <hr>
180
- <h2 class="section-title">AddToCart Event</h2>
181
- <p>AddToCart event will be added on add to cart button click and on cart page. It is required for Facebook Dynamic Product Ads.</p>
182
- <table class="layout">
183
-
184
- <tr>
185
- <td colspan="2" class="narrow">
186
- <input type="checkbox" name="pys[woo][on_add_to_cart_btn]" value="1" class="woo-option"
187
- <?php pys_checkbox_state( 'woo', 'on_add_to_cart_btn' ); ?> >
188
- <strong>Enable AddToCart on add to cart button</strong>
189
- </td>
190
- </tr>
191
-
192
- <tr>
193
- <td colspan="2" class="narrow">
194
-
195
- <?php
196
- $checked = get_option( 'woocommerce_cart_redirect_after_add' ) === 'yes' || pys_get_option( 'woo', 'on_add_to_cart_page' ) == "1";
197
- $disabled = get_option( 'woocommerce_cart_redirect_after_add' ) === 'yes';
198
- ?>
199
-
200
- <input type="checkbox" name="pys[woo][on_add_to_cart_page]" value="1" class="woo-option"
201
- <?php checked( $checked ); disabled( $disabled ); ?> >
202
- <strong>Enable AddToCart on cart page</strong>
203
- <?php if ( $disabled ) : ?>
204
- <span class="help">In order to disable the event you need to turn off the "Redirect to the cart
205
- page after successful addition" option from <a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=products' ); ?>"
206
- target="_blank">WooCommerce</a> settings</span>
207
- <?php endif; ?>
208
- </td>
209
- </tr>
210
-
211
- <tr class="tall">
212
- <td colspan="2" class="narrow">
213
- <input type="checkbox" name="pys[woo][on_add_to_cart_checkout]" value="1" class="woo-option"
214
- <?php pys_checkbox_state( 'woo', 'on_add_to_cart_checkout' ); ?> >
215
- <strong>Enable AddToCart on checkout page</strong>
216
- </td>
217
- </tr>
218
-
219
- <tr>
220
- <td></td>
221
- <td>
222
- <?php pys_checkbox( 'woo', 'enable_add_to_cart_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
223
- <span class="help">Add value and currency - Important for ROI measurement</span>
224
- </td>
225
- </tr>
226
-
227
- <tr>
228
- <td class="alignright"><p class="label big">Define value:</p></td>
229
- <td></td>
230
- </tr>
231
-
232
- <tr>
233
- <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
234
- <td>
235
- <input type="radio" name="pys[woo][add_to_cart_value_option]" value="price"
236
- <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'price' ); ?> >
237
- </td>
238
- </tr>
239
-
240
- <tr class="disabled">
241
- <td class="alignright"><p class="label">Percent of product price</p></td>
242
- <td>
243
- <input type="radio">
244
- <input type="text">%
245
- </td>
246
- </tr>
247
-
248
- <tr>
249
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
250
- <td>
251
- <input type="radio" name="pys[woo][add_to_cart_value_option]" value="global"
252
- <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'global' ); ?> >
253
- <input type="text" name="pys[woo][add_to_cart_global_value]" value="<?php echo pys_get_option( 'woo', 'add_to_cart_global_value' ); ?>">
254
- </td>
255
- </tr>
256
-
257
- <tr>
258
- <td></td>
259
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
260
- <strong>enable all value options</strong></td>
261
- </tr>
262
-
263
- </table>
264
-
265
- <hr>
266
- <h2 class="section-title">InitiateCheckout Event</h2>
267
- <p>InitiateCheckout event will be enabled on the Checkout page. It is not mandatory for Facebook Dynamic Product Ads, but it is better to keep it on.</p>
268
- <table class="layout">
269
-
270
- <tr class="tall">
271
- <td colspan="2" class="narrow">
272
-
273
- <input type="checkbox" name="pys[woo][on_checkout_page]" value="1" class="woo-option"
274
- <?php pys_checkbox_state( 'woo', 'on_checkout_page' ); ?> >
275
- <strong>Enable InitiateCheckout on Checkout page</strong>
276
-
277
- </td>
278
- </tr>
279
-
280
- <tr>
281
- <td></td>
282
- <td>
283
- <?php pys_checkbox( 'woo', 'enable_checkout_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
284
- <span class="help">Add value and currency - Important for ROI measurement</span>
285
- </td>
286
- </tr>
287
-
288
- <tr>
289
- <td class="alignright"><p class="label big">Define value:</p></td>
290
- <td></td>
291
- </tr>
292
-
293
- <tr>
294
- <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
295
- <td>
296
- <input type="radio" name="pys[woo][checkout_value_option]" value="price"
297
- <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'price' ); ?> >
298
- </td>
299
- </tr>
300
-
301
- <tr class="disabled">
302
- <td class="alignright"><p class="label">Percent of products value (subtotal)</p></td>
303
- <td>
304
- <input type="radio">
305
- <input type="text">%
306
- </td>
307
- </tr>
308
-
309
- <tr>
310
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
311
- <td>
312
- <input type="radio" name="pys[woo][checkout_value_option]" value="global"
313
- <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'global' ); ?> >
314
- <input type="text" name="pys[woo][checkout_global_value]" value="<?php echo pys_get_option( 'woo', 'checkout_global_value' ); ?>">
315
- </td>
316
- </tr>
317
-
318
- <tr>
319
- <td></td>
320
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
321
- <strong>enable all value options</strong></td>
322
- </tr>
323
-
324
- </table>
325
-
326
- <hr>
327
- <h2 class="section-title">Purchase Event</h2>
328
- <p>Purchase event will be enabled on the Thank You page. It is mandatory for Facebook Dynamic Product Ads.</p>
329
- <table class="layout">
330
-
331
- <tr class="tall">
332
- <td colspan="2" class="narrow">
333
-
334
- <input type="checkbox" name="pys[woo][on_thank_you_page]" value="1" class="woo-option"
335
- <?php pys_checkbox_state( 'woo', 'on_thank_you_page' ); ?> >
336
- <strong>Enable Purchase event on Thank You page</strong>
337
-
338
- </td>
339
- </tr>
340
-
341
- <tr>
342
- <td></td>
343
- <td>
344
- <?php pys_checkbox( 'woo', 'enable_purchase_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
345
- <span class="help">Add value and currency - <strong>Very important for ROI measurement</strong></span>
346
- </td>
347
- </tr>
348
-
349
- <tr>
350
- <td class="alignright disabled"><p class="label"><?php _e( 'Fire the event on transaction only', 'pys' );
351
- ?></p></td>
352
- <td>
353
- <select disabled>
354
- <option><?php _e( 'Off', 'pys' ); ?></option>
355
- </select>- <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
356
- <span class="help"><?php _e( 'This will avoid the Purchase event to be fired when the order-received page is visited but no transaction has occurred. <b>It will improve conversion tracking.</b>', 'pys' ); ?></span>
357
- </td>
358
- </tr>
359
-
360
- <tr>
361
- <td class="alignright"><p class="label big">Define value:</p></td>
362
- <td></td>
363
- </tr>
364
-
365
- <tr class="disabled">
366
- <td class="alignright"><p class="label">Transport is:</p></td>
367
- <td>
368
- <select disabled>
369
- <option selected>Included</option>
370
- </select>
371
- </td>
372
- </tr>
373
-
374
- <tr>
375
- <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
376
- <td>
377
- <input type="radio" name="pys[woo][purchase_value_option]" value="total"
378
- <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'total' ); ?> >
379
- </td>
380
- </tr>
381
-
382
- <tr class="disabled">
383
- <td class="alignright"><p class="label">Percent of Total</p></td>
384
- <td>
385
- <input type="radio">
386
- <input type="text">%
387
- </td>
388
- </tr>
389
-
390
- <tr class="tall">
391
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
392
- <td>
393
- <input type="radio" name="pys[woo][purchase_value_option]" value="global"
394
- <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'global' ); ?> >
395
- <input type="text" name="pys[woo][purchase_global_value]" value="<?php echo pys_get_option( 'woo', 'purchase_global_value' ); ?>">
396
- </td>
397
- </tr>
398
-
399
- <tr class="tall">
400
- <td></td>
401
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
402
- <strong>enable all value options</strong></td>
403
- </tr>
404
-
405
- <tr>
406
- <td class="alignright"><p class="label big">Custom Audience Optimization:</p></td>
407
- <td>
408
- <span class="help"><strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
409
- </td>
410
- </tr>
411
-
412
- <tr class="disabled">
413
- <td class="alignright"></td>
414
- <td>
415
- <input type="checkbox">
416
- <strong>Add Town, State and Country parameters</strong>
417
- <span class="help">Will pull <code>town</code>, <code>state</code> and <code>country</code></span>
418
-
419
- </td>
420
- </tr>
421
-
422
- <tr class="disabled">
423
- <td></td>
424
- <td>
425
- <input type="checkbox">
426
- <strong>Add Payment Method parameter</strong>
427
- <span class="help">Will pull <code>payment</code></span>
428
-
429
- </td>
430
- </tr>
431
-
432
- <tr class="disabled">
433
- <td></td>
434
- <td>
435
- <input type="checkbox">
436
- <strong>Add Shipping Method parameter</strong>
437
- <span class="help">Will pull <code>shipping</code></span>
438
- </td>
439
- </tr>
440
-
441
- <tr class="disabled">
442
- <td></td>
443
- <td>
444
- <input type="checkbox">
445
- <strong>Add Coupons parameter</strong>
446
- <span class="help">Will pull <code>coupon_used</code> and <code>coupon_name</code></span>
447
- </td>
448
- </tr>
449
-
450
- </table>
451
-
452
- <p><strong>Important:</strong> For the Purchase Event to work, the client must be redirected on the default WooCommerce Thank You page after payment.</p>
453
-
454
- <hr>
455
- <h2 class="section-title">WooCommerce Affiliate Products Events</h2>
456
- <p>You can add an event that will trigger each time an affiliate WooCommerce product button is clicked.</p>
457
- <table class="layout">
458
-
459
- <tr class="tall">
460
- <td colspan="2" class="narrow">
461
- <input type="checkbox" disabled><strong>Activate WooCommerce Affiliate Products Events - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></strong>
462
- </td>
463
- </tr>
464
-
465
- <tr class="disabled">
466
- <td class="alignright"><p class="label">Event type:</p></td>
467
- <td>
468
- <input type="radio" checked>
469
- <select disabled>
470
- <option selected>Lead</option>
471
- </select>
472
- </td>
473
- </tr>
474
-
475
- <tr class="disabled tall">
476
- <td class="alignright"><p class="label">Name of custom event:</p></td>
477
- <td>
478
- <input type="radio">
479
- <input type="text">
480
- <span class="help">* The Affiliate event will have all the parameters values specific for selected event.</span>
481
- <span class="help">* The Custom Affiliate event will have value, currency, content_name, content_type, content_ids.</span>
482
- </td>
483
- </tr>
484
-
485
- <tr class="disabled">
486
- <td class="alignright"><p class="label">Do not pull event value</p></td>
487
- <td>
488
- <input type="radio" checked>
489
- </td>
490
- </tr>
491
-
492
- <tr class="disabled">
493
- <td class="alignright"><p class="label">Event Value = Product Price</p></td>
494
- <td>
495
- <input type="radio">
496
- </td>
497
- </tr>
498
-
499
- <tr class="disabled">
500
- <td class="alignright"><p class="label">Use Global value</p></td>
501
- <td>
502
- <input type="radio">
503
- <input type="text">
504
- <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
505
- </td>
506
- </tr>
507
-
508
- </table>
509
-
510
- <hr>
511
- <h2 class="section-title">WooCommerce PayPal Standard Events</h2>
512
- <p>You can add an event that will trigger PayPal Standard button click.</p>
513
- <table class="layout">
514
-
515
- <tr class="tall">
516
- <td colspan="2" class="narrow">
517
- <input type="checkbox" disabled><strong>Activate PayPal Standard Events - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></strong>
518
- </td>
519
- </tr>
520
-
521
- <tr class="disabled">
522
- <td class="alignright"><p class="label">Event type:</p></td>
523
- <td>
524
- <input type="radio" checked>
525
- <select disabled>
526
- <option selected>InitiatePayment</option>
527
- </select>
528
- </td>
529
- </tr>
530
-
531
- <tr class="disabled tall">
532
- <td class="alignright"><p class="label">Name of custom event:</p></td>
533
- <td>
534
- <input type="radio">
535
- <input type="text">
536
- <span class="help">* The PayPal Standard event will have all the parameters values specific for selected event.</span>
537
- <span class="help">* The Custom Affiliate event will have value, currency, content_type, content_ids.</span>
538
- </td>
539
- </tr>
540
-
541
- <tr class="disabled">
542
- <td class="alignright"><p class="label">Do not pull event value</p></td>
543
- <td>
544
- <input type="radio" checked>
545
- </td>
546
- </tr>
547
-
548
- <tr class="disabled">
549
- <td class="alignright"><p class="label">Event Value = Cart Total</p></td>
550
- <td>
551
- <input type="radio">
552
- </td>
553
- </tr>
554
-
555
- <tr class="disabled">
556
- <td class="alignright"><p class="label">Use Global value</p></td>
557
- <td>
558
- <input type="radio">
559
- <input type="text">
560
- <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
561
- </td>
562
- </tr>
563
-
564
- </table>
565
-
566
- <hr>
567
-
568
- <table class="layout">
569
-
570
- <tr class="tall">
571
- <td colspan="2" class="narrow">
572
- <p>This plugin can do a lot of useful stuff, but if you want your ads to shine, follow the steps of other experience marketers and upgrade to the Pro version.<br><a href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank"><strong>Click Here for a Super Offer</strong></a></p>
573
- </td>
574
- </tr>
575
-
576
- <tr>
577
- <td class="alignright">
578
- <p class="label big">Activate WooCommerce Pixel Settings</p>
579
- </td>
580
- <td>
581
- <input type="checkbox" name="pys[woo][enabled]" value="1"
582
- <?php pys_checkbox_state( 'woo', 'enabled' ); ?> >
583
- </td>
584
- </tr>
585
-
586
- </table>
587
-
588
- <button class="pys-btn pys-btn-blue pys-btn-big aligncenter">Save Settings</button>
589
-
590
- </div>
591
  </div>
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ ?>
8
+
9
+ <div class="pys-box">
10
+ <div class="pys-col pys-col-full">
11
+ <h2 class="section-title">WooCommerce Pixel Settings</h2>
12
+ <p>Add all necessary events on WooCommerce with just a few clicks. On this tab you will find powerful options to customize the Facebook Pixel for your store.</p>
13
+
14
+ <hr>
15
+ <h2 class="section-title">Facebook Dynamic Product Ads Pixel Settings</h2>
16
+ <table class="layout" id="woo_content_id">
17
+ <tr class="tall">
18
+ <td colspan="2" class="narrow">
19
+ <input type="checkbox" class="woo-events-toggle"><strong>Enable Facebook Dynamic Product Ads</strong>
20
+ <span class="help">This will automatically add ViewContent on product pages, AddToCart on add to cart button click and cart page, InitiateCheckout on checkout page and Purchase on thank you page. The events will have the required <code>content_ids</code> and <code>content_type</code> parameters.</span>
21
+ </td>
22
+ </tr>
23
+
24
+ <?php do_action( 'pys_fb_pixel_admin_woo_content_id_before' ); ?>
25
+
26
+ <tr class="content_id">
27
+ <td></td>
28
+ <td>
29
+ <?php pys_checkbox( 'woo', 'variation_id', null, 'main' ); ?>
30
+ <?php _e( 'Treat variable products like simple products', 'pys' ); ?>
31
+
32
+ <span class="help">Turn this option ON when your Product Catalog doesn't include the variants for variable products.</span>
33
+ </td>
34
+ </tr>
35
+
36
+ <tr class="content_id">
37
+ <td class="alignright"><p class="label">content_ids:</p></td>
38
+ <td>
39
+ <select name="pys[woo][content_id]">
40
+ <option <?php selected( 'id', pys_get_option( 'woo', 'content_id' ) ); ?> value="id">Product ID
41
+ </option>
42
+ <option <?php selected( 'sku', pys_get_option( 'woo', 'content_id' ) ); ?> value="sku">Product SKU
43
+ </option>
44
+ </select>
45
+ </td>
46
+ </tr>
47
+
48
+ <tr>
49
+ <td></td>
50
+ <td>
51
+ <p><strong>Product Catalog Feed</strong> - use our dedicated plugin to create 100% Dynamic Ads compatible feeds with just a few clicks:</p>
52
+ <p><a href="http://www.pixelyoursite.com/product-catalog-facebook" target="_blank">Download Product Catalog Feed Plugin for a big discount</a></p>
53
+ </td>
54
+ </tr>
55
+ </table>
56
+
57
+ <hr>
58
+ <h2 class="section-title">PRO Options</h2>
59
+ <table class="layout">
60
+ <tr class="disabled" style="vertical-align: top;">
61
+ <td>
62
+
63
+ <h2>Custom Audiences Optimization</h2>
64
+
65
+ <input type="checkbox" disabled>Enable Additional Parameters
66
+ <span class="help">Product name will be pulled as <code>content_name</code>, and Product Category as <code>category_name</code> for all WooCommerce events.</span>
67
+ <span class="help" style="margin-bottom: 20px;">The number of items is <code>num_items</code> for InitiateCheckout and Purchase events.</span>
68
+
69
+ <input type="checkbox" disabled>Track tags
70
+ <span class="help">Will pull <code>tags</code> param on all WooCommerce events.</span>
71
+
72
+
73
+ </td>
74
+ <td>
75
+
76
+ <h2>Tax Options</h2>
77
+ Value: &nbsp;&nbsp;
78
+ <select>
79
+ <option selected>Includes Tax</option>
80
+ </select>
81
+
82
+ </td>
83
+ </tr>
84
+
85
+ <tr style="vertical-align: top;">
86
+ <td>
87
+
88
+ <p><strong>Important for Custom Audiences.</strong> Use this together with the General Event option.</p>
89
+ <p>Learn how to <strong>Create Powerful Custom Audiences</strong> based on Events: <strong><a href="http://www.pixelyoursite.com/general-event" target="_blank">Click to Download Your Free Guide</a></strong></p>
90
+ </td>
91
+ <td>
92
+
93
+ <p><strong>Unlock all the PRO features: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank">Upgrade NOW</a></strong></p>
94
+ </td>
95
+ </tr>
96
+
97
+
98
+ </table>
99
+
100
+ <hr>
101
+ <h2 class="section-title">ViewContent Event</h2>
102
+ <p>ViewContent is added on Product Pages and it is required for Facebook Dynamic Product Ads.</p>
103
+ <table class="layout">
104
+ <tr class="tall">
105
+ <td colspan="2" class="narrow">
106
+ <input type="checkbox" name="pys[woo][on_view_content]" value="1" class="woo-option"
107
+ <?php pys_checkbox_state( 'woo', 'on_view_content' ); ?> >
108
+ <strong>Enable ViewContent on Product Pages</strong>
109
+ </td>
110
+ </tr>
111
+
112
+ <tr>
113
+ <td class="alignright disabled"><p class="label">Delay</p></td>
114
+ <td>
115
+ <input type="number" disabled> seconds - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
116
+ <span class="help">Avoid retargeting bouncing users (It is better to add a lower time that the desired one because the pixel code will not load instantaneously). People that spent less time on the page will not be part of your Custom Audiences. You will not spend money retargeting them and your Lookalike Audiences will be more accurate.</span>
117
+ </td>
118
+ </tr>
119
+
120
+ <tr>
121
+ <td></td>
122
+ <td>
123
+ <?php pys_checkbox( 'woo', 'enable_view_content_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
124
+ <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
125
+ </td>
126
+ </tr>
127
+
128
+ <tr>
129
+ <td class="alignright"><p class="label big">Define value:</p></td>
130
+ <td></td>
131
+ </tr>
132
+
133
+ <tr>
134
+ <td class="alignright"><p class="label"><?php _e( 'Product price', 'pys' ); ?></p></td>
135
+ <td>
136
+ <input type="radio" name="pys[woo][view_content_value_option]" value="price"
137
+ <?php echo pys_radio_state( 'woo', 'view_content_value_option', 'price' ); ?> >
138
+ </td>
139
+ </tr>
140
+
141
+ <tr class="disabled">
142
+ <td class="alignright"><p class="label">Percent of product price</p></td>
143
+ <td>
144
+ <input type="radio">
145
+ <input type="text">%
146
+ </td>
147
+ </tr>
148
+
149
+ <tr>
150
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
151
+ <td>
152
+ <input type="radio" name="pys[woo][view_content_value_option]" value="global"
153
+ <?php echo pys_radio_state( 'woo', 'view_content_value_option', 'global' ); ?> >
154
+ <input type="text" name="pys[woo][view_content_global_value]" value="<?php echo pys_get_option( 'woo', 'view_content_global_value' ); ?>">
155
+ </td>
156
+ </tr>
157
+
158
+ <tr>
159
+ <td></td>
160
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
161
+ <strong>enable all value options</strong></td>
162
+ </tr>
163
+
164
+ </table>
165
+
166
+ <hr>
167
+ <h2 class="section-title">ViewCategory Event</h2>
168
+ <p>ViewCategory is added on product categories and it is required for Facebook Dynamic Product Ads.</p>
169
+ <table class="layout">
170
+ <tr class="">
171
+ <td colspan="2" class="narrow">
172
+ <input type="checkbox" name="pys[woo][on_view_category]" value="1" class="woo-option"
173
+ <?php pys_checkbox_state( 'woo', 'on_view_category' ); ?> >
174
+ <strong>Enable ViewCategory on product categories</strong>
175
+ </td>
176
+ </tr>
177
+ </table>
178
+
179
+ <hr>
180
+ <h2 class="section-title">AddToCart Event</h2>
181
+ <p>AddToCart event will be added on add to cart button click and on cart page. It is required for Facebook Dynamic Product Ads.</p>
182
+ <table class="layout">
183
+
184
+ <tr>
185
+ <td colspan="2" class="narrow">
186
+ <input type="checkbox" name="pys[woo][on_add_to_cart_btn]" value="1" class="woo-option"
187
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_btn' ); ?>>
188
+ <strong>Enable AddToCart on add to cart button</strong>
189
+ </td>
190
+ </tr>
191
+
192
+ <tr>
193
+ <td colspan="2" class="narrow">
194
+
195
+ <input type="checkbox" name="pys[woo][on_add_to_cart_page]" value="1" class="woo-option"
196
+ <?php checked( pys_get_option( 'woo', 'on_add_to_cart_page' ) ); ?>>
197
+ <strong>Enable AddToCart on cart page</strong>
198
+ </td>
199
+ </tr>
200
+
201
+ <tr class="tall">
202
+ <td colspan="2" class="narrow">
203
+ <input type="checkbox" name="pys[woo][on_add_to_cart_checkout]" value="1" class="woo-option"
204
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_checkout' ); ?> >
205
+ <strong>Enable AddToCart on checkout page</strong>
206
+ </td>
207
+ </tr>
208
+
209
+ <tr>
210
+ <td></td>
211
+ <td>
212
+ <?php pys_checkbox( 'woo', 'enable_add_to_cart_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
213
+ <span class="help">Add value and currency - Important for ROI measurement</span>
214
+ </td>
215
+ </tr>
216
+
217
+ <tr>
218
+ <td class="alignright"><p class="label big">Define value:</p></td>
219
+ <td></td>
220
+ </tr>
221
+
222
+ <tr>
223
+ <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
224
+ <td>
225
+ <input type="radio" name="pys[woo][add_to_cart_value_option]" value="price"
226
+ <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'price' ); ?> >
227
+ </td>
228
+ </tr>
229
+
230
+ <tr class="disabled">
231
+ <td class="alignright"><p class="label">Percent of product price</p></td>
232
+ <td>
233
+ <input type="radio">
234
+ <input type="text">%
235
+ </td>
236
+ </tr>
237
+
238
+ <tr>
239
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
240
+ <td>
241
+ <input type="radio" name="pys[woo][add_to_cart_value_option]" value="global"
242
+ <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'global' ); ?> >
243
+ <input type="text" name="pys[woo][add_to_cart_global_value]" value="<?php echo pys_get_option( 'woo', 'add_to_cart_global_value' ); ?>">
244
+ </td>
245
+ </tr>
246
+
247
+ <tr>
248
+ <td></td>
249
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
250
+ <strong>enable all value options</strong></td>
251
+ </tr>
252
+
253
+ </table>
254
+
255
+ <hr>
256
+ <h2 class="section-title">InitiateCheckout Event</h2>
257
+ <p>InitiateCheckout event will be enabled on the Checkout page. It is not mandatory for Facebook Dynamic Product Ads, but it is better to keep it on.</p>
258
+ <table class="layout">
259
+
260
+ <tr class="tall">
261
+ <td colspan="2" class="narrow">
262
+
263
+ <input type="checkbox" name="pys[woo][on_checkout_page]" value="1" class="woo-option"
264
+ <?php pys_checkbox_state( 'woo', 'on_checkout_page' ); ?> >
265
+ <strong>Enable InitiateCheckout on Checkout page</strong>
266
+
267
+ </td>
268
+ </tr>
269
+
270
+ <tr>
271
+ <td></td>
272
+ <td>
273
+ <?php pys_checkbox( 'woo', 'enable_checkout_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
274
+ <span class="help">Add value and currency - Important for ROI measurement</span>
275
+ </td>
276
+ </tr>
277
+
278
+ <tr>
279
+ <td class="alignright"><p class="label big">Define value:</p></td>
280
+ <td></td>
281
+ </tr>
282
+
283
+ <tr>
284
+ <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
285
+ <td>
286
+ <input type="radio" name="pys[woo][checkout_value_option]" value="price"
287
+ <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'price' ); ?> >
288
+ </td>
289
+ </tr>
290
+
291
+ <tr class="disabled">
292
+ <td class="alignright"><p class="label">Percent of products value (subtotal)</p></td>
293
+ <td>
294
+ <input type="radio">
295
+ <input type="text">%
296
+ </td>
297
+ </tr>
298
+
299
+ <tr>
300
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
301
+ <td>
302
+ <input type="radio" name="pys[woo][checkout_value_option]" value="global"
303
+ <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'global' ); ?> >
304
+ <input type="text" name="pys[woo][checkout_global_value]" value="<?php echo pys_get_option( 'woo', 'checkout_global_value' ); ?>">
305
+ </td>
306
+ </tr>
307
+
308
+ <tr>
309
+ <td></td>
310
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
311
+ <strong>enable all value options</strong></td>
312
+ </tr>
313
+
314
+ </table>
315
+
316
+ <hr>
317
+ <h2 class="section-title">Purchase Event</h2>
318
+ <p>Purchase event will be enabled on the Thank You page. It is mandatory for Facebook Dynamic Product Ads.</p>
319
+ <table class="layout">
320
+
321
+ <tr class="tall">
322
+ <td colspan="2" class="narrow">
323
+
324
+ <input type="checkbox" name="pys[woo][on_thank_you_page]" value="1" class="woo-option"
325
+ <?php pys_checkbox_state( 'woo', 'on_thank_you_page' ); ?> >
326
+ <strong>Enable Purchase event on Thank You page</strong>
327
+
328
+ </td>
329
+ </tr>
330
+
331
+ <tr>
332
+ <td></td>
333
+ <td>
334
+ <?php pys_checkbox( 'woo', 'enable_purchase_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
335
+ <span class="help">Add value and currency - <strong>Very important for ROI measurement</strong></span>
336
+ </td>
337
+ </tr>
338
+
339
+ <tr>
340
+ <td class="alignright disabled"><p class="label"><?php _e( 'Fire the event on transaction only', 'pys' );
341
+ ?></p></td>
342
+ <td>
343
+ <select disabled>
344
+ <option><?php _e( 'Off', 'pys' ); ?></option>
345
+ </select>- <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
346
+ <span class="help"><?php _e( 'This will avoid the Purchase event to be fired when the order-received page is visited but no transaction has occurred. <b>It will improve conversion tracking.</b>', 'pys' ); ?></span>
347
+ </td>
348
+ </tr>
349
+
350
+ <tr>
351
+ <td class="alignright"><p class="label big">Define value:</p></td>
352
+ <td></td>
353
+ </tr>
354
+
355
+ <tr class="disabled">
356
+ <td class="alignright"><p class="label">Transport is:</p></td>
357
+ <td>
358
+ <select disabled>
359
+ <option selected>Included</option>
360
+ </select>
361
+ </td>
362
+ </tr>
363
+
364
+ <tr>
365
+ <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
366
+ <td>
367
+ <input type="radio" name="pys[woo][purchase_value_option]" value="total"
368
+ <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'total' ); ?> >
369
+ </td>
370
+ </tr>
371
+
372
+ <tr class="disabled">
373
+ <td class="alignright"><p class="label">Percent of Total</p></td>
374
+ <td>
375
+ <input type="radio">
376
+ <input type="text">%
377
+ </td>
378
+ </tr>
379
+
380
+ <tr class="tall">
381
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
382
+ <td>
383
+ <input type="radio" name="pys[woo][purchase_value_option]" value="global"
384
+ <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'global' ); ?> >
385
+ <input type="text" name="pys[woo][purchase_global_value]" value="<?php echo pys_get_option( 'woo', 'purchase_global_value' ); ?>">
386
+ </td>
387
+ </tr>
388
+
389
+ <tr class="tall">
390
+ <td></td>
391
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
392
+ <strong>enable all value options</strong></td>
393
+ </tr>
394
+
395
+ <tr>
396
+ <td class="alignright"><p class="label big">Custom Audience Optimization:</p></td>
397
+ <td>
398
+ <span class="help"><strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
399
+ </td>
400
+ </tr>
401
+
402
+ <tr class="disabled">
403
+ <td class="alignright"></td>
404
+ <td>
405
+ <input type="checkbox">
406
+ <strong>Add Town, State and Country parameters</strong>
407
+ <span class="help">Will pull <code>town</code>, <code>state</code> and <code>country</code></span>
408
+
409
+ </td>
410
+ </tr>
411
+
412
+ <tr class="disabled">
413
+ <td></td>
414
+ <td>
415
+ <input type="checkbox">
416
+ <strong>Add Payment Method parameter</strong>
417
+ <span class="help">Will pull <code>payment</code></span>
418
+
419
+ </td>
420
+ </tr>
421
+
422
+ <tr class="disabled">
423
+ <td></td>
424
+ <td>
425
+ <input type="checkbox">
426
+ <strong>Add Shipping Method parameter</strong>
427
+ <span class="help">Will pull <code>shipping</code></span>
428
+ </td>
429
+ </tr>
430
+
431
+ <tr class="disabled">
432
+ <td></td>
433
+ <td>
434
+ <input type="checkbox">
435
+ <strong>Add Coupons parameter</strong>
436
+ <span class="help">Will pull <code>coupon_used</code> and <code>coupon_name</code></span>
437
+ </td>
438
+ </tr>
439
+
440
+ </table>
441
+
442
+ <p><strong>Important:</strong> For the Purchase Event to work, the client must be redirected on the default WooCommerce Thank You page after payment.</p>
443
+
444
+ <hr>
445
+ <h2 class="section-title">WooCommerce Affiliate Products Events</h2>
446
+ <p>You can add an event that will trigger each time an affiliate WooCommerce product button is clicked.</p>
447
+ <table class="layout">
448
+
449
+ <tr class="tall">
450
+ <td colspan="2" class="narrow">
451
+ <input type="checkbox" disabled><strong>Activate WooCommerce Affiliate Products Events - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></strong>
452
+ </td>
453
+ </tr>
454
+
455
+ <tr class="disabled">
456
+ <td class="alignright"><p class="label">Event type:</p></td>
457
+ <td>
458
+ <input type="radio" checked>
459
+ <select disabled>
460
+ <option selected>Lead</option>
461
+ </select>
462
+ </td>
463
+ </tr>
464
+
465
+ <tr class="disabled tall">
466
+ <td class="alignright"><p class="label">Name of custom event:</p></td>
467
+ <td>
468
+ <input type="radio">
469
+ <input type="text">
470
+ <span class="help">* The Affiliate event will have all the parameters values specific for selected event.</span>
471
+ <span class="help">* The Custom Affiliate event will have value, currency, content_name, content_type, content_ids.</span>
472
+ </td>
473
+ </tr>
474
+
475
+ <tr class="disabled">
476
+ <td class="alignright"><p class="label">Do not pull event value</p></td>
477
+ <td>
478
+ <input type="radio" checked>
479
+ </td>
480
+ </tr>
481
+
482
+ <tr class="disabled">
483
+ <td class="alignright"><p class="label">Event Value = Product Price</p></td>
484
+ <td>
485
+ <input type="radio">
486
+ </td>
487
+ </tr>
488
+
489
+ <tr class="disabled">
490
+ <td class="alignright"><p class="label">Use Global value</p></td>
491
+ <td>
492
+ <input type="radio">
493
+ <input type="text">
494
+ <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
495
+ </td>
496
+ </tr>
497
+
498
+ </table>
499
+
500
+ <hr>
501
+ <h2 class="section-title">WooCommerce PayPal Standard Events</h2>
502
+ <p>You can add an event that will trigger PayPal Standard button click.</p>
503
+ <table class="layout">
504
+
505
+ <tr class="tall">
506
+ <td colspan="2" class="narrow">
507
+ <input type="checkbox" disabled><strong>Activate PayPal Standard Events - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></strong>
508
+ </td>
509
+ </tr>
510
+
511
+ <tr class="disabled">
512
+ <td class="alignright"><p class="label">Event type:</p></td>
513
+ <td>
514
+ <input type="radio" checked>
515
+ <select disabled>
516
+ <option selected>InitiatePayment</option>
517
+ </select>
518
+ </td>
519
+ </tr>
520
+
521
+ <tr class="disabled tall">
522
+ <td class="alignright"><p class="label">Name of custom event:</p></td>
523
+ <td>
524
+ <input type="radio">
525
+ <input type="text">
526
+ <span class="help">* The PayPal Standard event will have all the parameters values specific for selected event.</span>
527
+ <span class="help">* The Custom Affiliate event will have value, currency, content_type, content_ids.</span>
528
+ </td>
529
+ </tr>
530
+
531
+ <tr class="disabled">
532
+ <td class="alignright"><p class="label">Do not pull event value</p></td>
533
+ <td>
534
+ <input type="radio" checked>
535
+ </td>
536
+ </tr>
537
+
538
+ <tr class="disabled">
539
+ <td class="alignright"><p class="label">Event Value = Cart Total</p></td>
540
+ <td>
541
+ <input type="radio">
542
+ </td>
543
+ </tr>
544
+
545
+ <tr class="disabled">
546
+ <td class="alignright"><p class="label">Use Global value</p></td>
547
+ <td>
548
+ <input type="radio">
549
+ <input type="text">
550
+ <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
551
+ </td>
552
+ </tr>
553
+
554
+ </table>
555
+
556
+ <hr>
557
+
558
+ <table class="layout">
559
+
560
+ <tr class="tall">
561
+ <td colspan="2" class="narrow">
562
+ <p>This plugin can do a lot of useful stuff, but if you want your ads to shine, follow the steps of other experience marketers and upgrade to the Pro version.<br><a href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank"><strong>Click Here for a Super Offer</strong></a></p>
563
+ </td>
564
+ </tr>
565
+
566
+ <tr>
567
+ <td class="alignright">
568
+ <p class="label big">Activate WooCommerce Pixel Settings</p>
569
+ </td>
570
+ <td>
571
+ <input type="checkbox" name="pys[woo][enabled]" value="1"
572
+ <?php pys_checkbox_state( 'woo', 'enabled' ); ?> >
573
+ </td>
574
+ </tr>
575
+
576
+ </table>
577
+
578
+ <button class="pys-btn pys-btn-blue pys-btn-big aligncenter">Save Settings</button>
579
+
580
+ </div>
 
 
 
 
 
 
 
 
 
 
581
  </div>
inc/integrations/facebook-for-woocommerce.php CHANGED
@@ -1,233 +1,233 @@
1
- <?php
2
-
3
- /**
4
- * Manage integration with Facebook for WooCommerce plugin.
5
- *
6
- * When Facebook for WooCommerce is activated this integration completely removes
7
- * default Facebook for WooCommerce pixels and replaces them with PYS's. Also, new "Pixel ID format" option added to
8
- * PYS WooCommerce tab where user can decide what format to use in pixel: PYS default or Facebook for WooCommerce.
9
- */
10
-
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit; // Exit if accessed directly.
13
- }
14
-
15
- if ( class_exists( 'WC_Facebookcommerce' ) && ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
16
-
17
- /**
18
- * Declare fake WC_Facebookcommerce_EventsTracker class to remove all unwanted front-end pixel events.
19
- */
20
-
21
- /** @noinspection PhpUndefinedClassInspection */
22
- class WC_Facebookcommerce_EventsTracker {
23
-
24
- public function __construct( $pixel_id = null, $user_info = null ) {
25
- }
26
-
27
- public function inject_base_pixel() {
28
- }
29
-
30
- public function inject_view_category_event() {
31
- }
32
-
33
- public function inject_search_event() {
34
- }
35
-
36
- public function inject_view_content_event() {
37
- }
38
-
39
- public function inject_add_to_cart_event() {
40
- }
41
-
42
- public function inject_initiate_checkout_event() {
43
- }
44
-
45
- public function inject_purchase_event( $order_id ) {
46
- }
47
-
48
- public function inject_base_pixel_noscript() {
49
- }
50
-
51
- }
52
-
53
- endif;
54
-
55
- if ( class_exists( 'WC_Facebookcommerce' ) ) :
56
-
57
- /**
58
- * Setup PYS hooks and filters for Facebook for WooCommerce related options and pixel ID output format.
59
- */
60
-
61
- add_filter( 'pys_fb_pixel_woo_product_content_id', 'fb_for_woo_pys_fb_pixel_woo_product_content_id', 10, 4 );
62
- function fb_for_woo_pys_fb_pixel_woo_product_content_id( $content_id, $product_id, $content_id_format ) {
63
-
64
- // use value as is
65
- if( $content_id_format !== 'facebook_for_woocommerce' ) {
66
- return $content_id;
67
- }
68
-
69
- $product = wc_get_product($product_id);
70
-
71
- if ( ! $product ) {
72
- return $content_id;
73
- }
74
-
75
- if ( $sku = $product->get_sku() ) {
76
- $value = $product->get_sku() . '_' . $product->get_id();
77
- } else {
78
- $value = 'wc_post_id_' . $product->get_id();
79
- }
80
-
81
- return array( $value );
82
-
83
- }
84
-
85
- add_filter( 'pys_event_params', 'fb_for_woo_pys_event_params', 99, 2 );
86
- function fb_for_woo_pys_event_params( $params, $event ) {
87
-
88
- if ( pys_get_option( 'woo', 'content_id_format' ) == 'facebook_for_woocommerce' ) {
89
- // Unset 'contents' parameter to avoid conflict with Facebook for WooCommerce plugin as of it is not
90
- // support new Dynamic Ads parameters
91
- unset( $params['contents'] );
92
- }
93
-
94
- return $params;
95
-
96
- }
97
-
98
- add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
99
- function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
100
-
101
- if( $content_id_format !== 'facebook_for_woocommerce' ) {
102
- return $content_type;
103
- }
104
-
105
- if ( $product_type == 'variable' ) {
106
- return 'product_group';
107
- } else {
108
- return 'product';
109
- }
110
-
111
- }
112
-
113
- add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
114
- function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
115
-
116
- if ( $content_id_format !== 'facebook_for_woocommerce' ) {
117
- return $product_id;
118
- }
119
-
120
- if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
121
- return $cart_item['variation_id'];
122
- } else {
123
- return $cart_item['product_id'];
124
- }
125
-
126
- }
127
-
128
- add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
129
- function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
130
-
131
- $setting_defaults['woo']['content_id_format'] = 'default';
132
-
133
- return $setting_defaults;
134
-
135
- }
136
-
137
- add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
138
- function pys_fb_pixel_admin_woo_content_id_before() {
139
-
140
- ?>
141
-
142
- <tr class="tall">
143
- <td colspan="2" class="narrow">
144
- <p><strong>It looks like you're using both PixelYourSite and Facebook Ads Extension. Good, because they can do a great job together!</strong></p>
145
- <p>Facebook Ads Extension is a useful free tool that lets you import your products to a Facebook shop and adds a very basic Facebook pixel on your site. PixelYourSite is a dedicated plugin that supercharges your Facebook Pixel with extremely useful features.</p>
146
-
147
- <p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
148
-
149
- <p style="margin-top: 0;">
150
- <input type="radio" name="pys[woo][content_id_format]" value="facebook_for_woocommerce" <?php echo pys_radio_state( 'woo', 'content_id_format', 'facebook_for_woocommerce' ); ?>><strong>Use Facebook for WooCommerce extension content_id logic</strong>
151
- </p>
152
-
153
- <p style="margin-top: 0;">
154
- <input type="radio" name="pys[woo][content_id_format]" value="default" <?php echo pys_radio_state( 'woo', 'content_id_format', 'default' ); ?>><strong>PixelYourSite content_id logic</strong>
155
- </p>
156
-
157
- <p><em>* If you plan to use the product catalog created by Facebook for WooCommerce Extension, use the Facebook for WooCommerce Extension ID. If you plan to use older product catalogs, or new ones created with other plugins, it's better to keep the default PixelYourSite settings.</em></p>
158
- </td>
159
- </tr>
160
-
161
-
162
- <script type="text/javascript">
163
- jQuery(document).ready(function ($) {
164
-
165
- $('input[name="pys[woo][content_id_format]"]').change(function (e) {
166
- toggleContentIDFormatControls();
167
- });
168
-
169
- toggleContentIDFormatControls();
170
-
171
- function toggleContentIDFormatControls() {
172
-
173
- var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
174
-
175
- if (format == 'default') {
176
- $('.content_id', '#woo_content_id' ).show();
177
- } else {
178
- $('.content_id', '#woo_content_id').hide();
179
- }
180
-
181
- }
182
-
183
- });
184
- </script>
185
-
186
- <?php
187
- }
188
-
189
- add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
190
- function fb_for_woo_admin_notice_display() {
191
-
192
- $user_id = get_current_user_id();
193
-
194
- if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
195
- return;
196
- }
197
-
198
- ?>
199
-
200
- <div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
201
- <p>You're using both PixelYourSite and Facebook for WooCommerce Extension. Good, because they can do a great job together! <strong><a href="<?php echo admin_url( 'admin.php?page=pixel-your-site&active_tab=woo#woo_content_id' ); ?>">Click here for more details</a></strong>.</p>
202
- </div>
203
-
204
- <script type="text/javascript">
205
- jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
206
-
207
- jQuery.ajax({
208
- url: ajaxurl,
209
- data: {
210
- action: 'fb_for_woo_admin_notice_dismiss',
211
- nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
212
- user_id: '<?php echo $user_id; ?>'
213
- }
214
- })
215
-
216
- })
217
- </script>
218
-
219
- <?php
220
- }
221
-
222
- add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
223
- function fb_for_woo_admin_notice_dismiss_handler() {
224
-
225
- if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
226
- return;
227
- }
228
-
229
- add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
230
-
231
- }
232
-
233
  endif;
1
+ <?php
2
+
3
+ /**
4
+ * Manage integration with Facebook for WooCommerce plugin.
5
+ *
6
+ * When Facebook for WooCommerce is activated this integration completely removes
7
+ * default Facebook for WooCommerce pixels and replaces them with PYS's. Also, new "Pixel ID format" option added to
8
+ * PYS WooCommerce tab where user can decide what format to use in pixel: PYS default or Facebook for WooCommerce.
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit; // Exit if accessed directly.
13
+ }
14
+
15
+ if ( class_exists( 'WC_Facebookcommerce' ) && ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
16
+
17
+ /**
18
+ * Declare fake WC_Facebookcommerce_EventsTracker class to remove all unwanted front-end pixel events.
19
+ */
20
+
21
+ /** @noinspection PhpUndefinedClassInspection */
22
+ class WC_Facebookcommerce_EventsTracker {
23
+
24
+ public function __construct( $pixel_id = null, $user_info = null ) {
25
+ }
26
+
27
+ public function inject_base_pixel() {
28
+ }
29
+
30
+ public function inject_view_category_event() {
31
+ }
32
+
33
+ public function inject_search_event() {
34
+ }
35
+
36
+ public function inject_view_content_event() {
37
+ }
38
+
39
+ public function inject_add_to_cart_event() {
40
+ }
41
+
42
+ public function inject_initiate_checkout_event() {
43
+ }
44
+
45
+ public function inject_purchase_event( $order_id ) {
46
+ }
47
+
48
+ public function inject_base_pixel_noscript() {
49
+ }
50
+
51
+ }
52
+
53
+ endif;
54
+
55
+ if ( class_exists( 'WC_Facebookcommerce' ) ) :
56
+
57
+ /**
58
+ * Setup PYS hooks and filters for Facebook for WooCommerce related options and pixel ID output format.
59
+ */
60
+
61
+ add_filter( 'pys_fb_pixel_woo_product_content_id', 'fb_for_woo_pys_fb_pixel_woo_product_content_id', 10, 4 );
62
+ function fb_for_woo_pys_fb_pixel_woo_product_content_id( $content_id, $product_id, $content_id_format ) {
63
+
64
+ // use value as is
65
+ if( $content_id_format !== 'facebook_for_woocommerce' ) {
66
+ return $content_id;
67
+ }
68
+
69
+ $product = wc_get_product($product_id);
70
+
71
+ if ( ! $product ) {
72
+ return $content_id;
73
+ }
74
+
75
+ if ( $sku = $product->get_sku() ) {
76
+ $value = $product->get_sku() . '_' . $product->get_id();
77
+ } else {
78
+ $value = 'wc_post_id_' . $product->get_id();
79
+ }
80
+
81
+ return array( $value );
82
+
83
+ }
84
+
85
+ add_filter( 'pys_event_params', 'fb_for_woo_pys_event_params', 99, 2 );
86
+ function fb_for_woo_pys_event_params( $params, $event ) {
87
+
88
+ if ( pys_get_option( 'woo', 'content_id_format' ) == 'facebook_for_woocommerce' ) {
89
+ // Unset 'contents' parameter to avoid conflict with Facebook for WooCommerce plugin as of it is not
90
+ // support new Dynamic Ads parameters
91
+ unset( $params['contents'] );
92
+ }
93
+
94
+ return $params;
95
+
96
+ }
97
+
98
+ add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
99
+ function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
100
+
101
+ if( $content_id_format !== 'facebook_for_woocommerce' ) {
102
+ return $content_type;
103
+ }
104
+
105
+ if ( $product_type == 'variable' ) {
106
+ return 'product_group';
107
+ } else {
108
+ return 'product';
109
+ }
110
+
111
+ }
112
+
113
+ add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
114
+ function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
115
+
116
+ if ( $content_id_format !== 'facebook_for_woocommerce' ) {
117
+ return $product_id;
118
+ }
119
+
120
+ if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
121
+ return $cart_item['variation_id'];
122
+ } else {
123
+ return $cart_item['product_id'];
124
+ }
125
+
126
+ }
127
+
128
+ add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
129
+ function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
130
+
131
+ $setting_defaults['woo']['content_id_format'] = 'default';
132
+
133
+ return $setting_defaults;
134
+
135
+ }
136
+
137
+ add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
138
+ function pys_fb_pixel_admin_woo_content_id_before() {
139
+
140
+ ?>
141
+
142
+ <tr class="tall">
143
+ <td colspan="2" class="narrow">
144
+ <p><strong>It looks like you're using both PixelYourSite and Facebook Ads Extension. Good, because they can do a great job together!</strong></p>
145
+ <p>Facebook Ads Extension is a useful free tool that lets you import your products to a Facebook shop and adds a very basic Facebook pixel on your site. PixelYourSite is a dedicated plugin that supercharges your Facebook Pixel with extremely useful features.</p>
146
+
147
+ <p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
148
+
149
+ <p style="margin-top: 0;">
150
+ <input type="radio" name="pys[woo][content_id_format]" value="facebook_for_woocommerce" <?php echo pys_radio_state( 'woo', 'content_id_format', 'facebook_for_woocommerce' ); ?>><strong>Use Facebook for WooCommerce extension content_id logic</strong>
151
+ </p>
152
+
153
+ <p style="margin-top: 0;">
154
+ <input type="radio" name="pys[woo][content_id_format]" value="default" <?php echo pys_radio_state( 'woo', 'content_id_format', 'default' ); ?>><strong>PixelYourSite content_id logic</strong>
155
+ </p>
156
+
157
+ <p><em>* If you plan to use the product catalog created by Facebook for WooCommerce Extension, use the Facebook for WooCommerce Extension ID. If you plan to use older product catalogs, or new ones created with other plugins, it's better to keep the default PixelYourSite settings.</em></p>
158
+ </td>
159
+ </tr>
160
+
161
+
162
+ <script type="text/javascript">
163
+ jQuery(document).ready(function ($) {
164
+
165
+ $('input[name="pys[woo][content_id_format]"]').change(function (e) {
166
+ toggleContentIDFormatControls();
167
+ });
168
+
169
+ toggleContentIDFormatControls();
170
+
171
+ function toggleContentIDFormatControls() {
172
+
173
+ var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
174
+
175
+ if (format == 'default') {
176
+ $('.content_id', '#woo_content_id' ).show();
177
+ } else {
178
+ $('.content_id', '#woo_content_id').hide();
179
+ }
180
+
181
+ }
182
+
183
+ });
184
+ </script>
185
+
186
+ <?php
187
+ }
188
+
189
+ add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
190
+ function fb_for_woo_admin_notice_display() {
191
+
192
+ $user_id = get_current_user_id();
193
+
194
+ if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
195
+ return;
196
+ }
197
+
198
+ ?>
199
+
200
+ <div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
201
+ <p>You're using both PixelYourSite and Facebook for WooCommerce Extension. Good, because they can do a great job together! <strong><a href="<?php echo admin_url( 'admin.php?page=pixel-your-site&active_tab=woo#woo_content_id' ); ?>">Click here for more details</a></strong>.</p>
202
+ </div>
203
+
204
+ <script type="text/javascript">
205
+ jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
206
+
207
+ jQuery.ajax({
208
+ url: ajaxurl,
209
+ data: {
210
+ action: 'fb_for_woo_admin_notice_dismiss',
211
+ nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
212
+ user_id: '<?php echo $user_id; ?>'
213
+ }
214
+ })
215
+
216
+ })
217
+ </script>
218
+
219
+ <?php
220
+ }
221
+
222
+ add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
223
+ function fb_for_woo_admin_notice_dismiss_handler() {
224
+
225
+ if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
226
+ return;
227
+ }
228
+
229
+ add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
230
+
231
+ }
232
+
233
  endif;
js/public.js CHANGED
@@ -11,57 +11,77 @@ jQuery(document).ready(function( $ ) {
11
  t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
12
  document,'script','https://connect.facebook.net/en_US/fbevents.js');
13
 
14
- var fbAddToCart = function ($button) {
 
 
 
 
 
15
 
16
- var data = {
17
- action: 'pys_woo_addtocart_params',
18
- product_id: undefined,
19
- variation_id: undefined,
20
- quantity: 1
21
- };
 
 
 
 
22
 
23
- $.each($button.data(), function (key, value) {
24
- data[key] = value;
25
  });
26
 
27
- var $variations_form = $button.closest('form.variations_form.cart'),
28
- $single_form = $button.closest('form.cart');
29
 
30
- if ($variations_form.length === 1) {
31
- data.product_id = parseInt($single_form.find('*[name="add-to-cart"]').val());
32
- data.variation_id = parseInt($variations_form.find('input[name="variation_id"]').val());
33
- data.quantity = parseInt($variations_form.find('input[name="quantity"]').val());
34
- } else if ($single_form.length === 1) {
35
- data.product_id = parseInt($single_form.find('*[name="add-to-cart"]').val());
36
- data.quantity = parseInt($single_form.find('input[name="quantity"]').val());
37
- }
 
38
 
39
- $.ajax({
40
- url: pys_fb_pixel_options.ajax_url,
41
- data: data,
42
- dataType: 'json',
43
- async: false,
44
- success: function (response) {
 
45
 
46
- if (!response || response.error) {
47
- return;
 
 
 
 
48
  }
49
 
50
- fbq('track', 'AddToCart', response.data);
 
 
51
 
52
  }
53
- });
54
 
55
- };
56
 
57
- /**
58
- * WooCommerce AddToCart on button
59
- */
60
- if (pys_fb_pixel_options.woo.addtocart_enabled && typeof wc_add_to_cart_params !== 'undefined'
61
- && wc_add_to_cart_params.cart_redirect_after_add !== 'yes') {
 
 
 
 
 
 
 
 
62
 
63
- $(document.body).on('added_to_cart', function (e, fragments, cart_hash, $button) {
64
- fbAddToCart($button);
65
  });
66
 
67
  }
11
  t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
12
  document,'script','https://connect.facebook.net/en_US/fbevents.js');
13
 
14
+ /**
15
+ * WooCommerce AddToCart on button
16
+ */
17
+ if (pys_fb_pixel_options.woo.addtocart_enabled) {
18
+
19
+ window.pys_woo_product_data = window.pys_woo_product_data || [];
20
 
21
+ // Loop, any kind of "simple" product, except external
22
+ $('.add_to_cart_button:not(.product_type_variable)').click(function (e) {
23
+
24
+ var product_id = $(this).data('product_id');
25
+
26
+ if (typeof product_id !== 'undefined') {
27
+ if (typeof pys_woo_product_data[product_id] !== 'undefined') {
28
+ fbq('track', 'AddToCart', pys_woo_product_data[product_id]);
29
+ }
30
+ }
31
 
 
 
32
  });
33
 
34
+ // Single Product
35
+ $('.single_add_to_cart_button').click(function (e) {
36
 
37
+ var $button = $(this),
38
+ $form = $button.closest('form'),
39
+ is_variable = false,
40
+ qty,
41
+ product_id = pys_fb_pixel_options.woo.product_id;
42
+
43
+ if ($button.hasClass('disabled')) {
44
+ return;
45
+ }
46
 
47
+ if ($form.length === 0) {
48
+ return; // is external product, not supported on Free
49
+ }
50
+
51
+ if ($form.hasClass('variations_form')) {
52
+ is_variable = true;
53
+ }
54
 
55
+ if (is_variable) {
56
+
57
+ qty = parseInt($form.find('input[name="quantity"]').val());
58
+
59
+ if (pys_fb_pixel_options.woo.product_data !== 'main') {
60
+ product_id = parseInt($form.find('input[name="variation_id"]').val());
61
  }
62
 
63
+ } else {
64
+
65
+ qty = parseInt($form.find('input[name="quantity"]').val());
66
 
67
  }
 
68
 
69
+ if (typeof pys_woo_product_data[product_id] !== 'undefined') {
70
 
71
+ var params = pys_woo_product_data[product_id];
72
+
73
+ // maybe customize value option
74
+ if (pys_fb_pixel_options.woo.product_value_enabled && pys_fb_pixel_options.woo.product_value_option !== 'global') {
75
+ params.value = params.value * qty;
76
+ }
77
+
78
+ // update contents qty param
79
+ params.contents[0].quantity = qty;
80
+
81
+ fbq('track', 'AddToCart', params);
82
+
83
+ }
84
 
 
 
85
  });
86
 
87
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: Facebook Pixel, New Facebook Pixel, Facebook Conversion Pixel, Facebook Pi
4
  Requires at least: 3.0.1
5
  Requires PHP: 5.3
6
  Tested up to: 4.9
7
- Stable tag: 5.2.1
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -300,6 +300,13 @@ We have an article about how to create Custom Reports:
300
 
301
  == Changelog ==
302
 
 
 
 
 
 
 
 
303
  = PixelYourSite 5.2.1 =
304
 
305
  * AddToCart small improvements to ensure compatibility with some themes using AJAX cart
4
  Requires at least: 3.0.1
5
  Requires PHP: 5.3
6
  Tested up to: 4.9
7
+ Stable tag: 5.3.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
300
 
301
  == Changelog ==
302
 
303
+ = PixelYourSite 5.3.0 =
304
+
305
+ * Additional improvements to the WooCommerce AddToCart event ("Cannot read property 'data' of undefined" error with some AJAX based themes)
306
+
307
+ * Fixing potential security issue
308
+
309
+
310
  = PixelYourSite 5.2.1 =
311
 
312
  * AddToCart small improvements to ensure compatibility with some themes using AJAX cart