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

Version Description

Download this release

Release Info

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

Code changes from version 5.0.8 to 5.0.9

facebook-pixel-master.php CHANGED
@@ -1,63 +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.0.8
9
- License: GPLv3
10
- */
11
-
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit; // Exit if accessed directly.
14
- }
15
-
16
- define( 'PYS_FREE_VERSION', '5.0.8' );
17
-
18
- if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
19
-
20
- /**
21
- * Check whatever PixelYourSite PRO version activated.
22
- *
23
- * @return bool
24
- */
25
- function pys_is_pixelyoursite_pro_active() {
26
-
27
- if ( ! function_exists( 'is_plugin_active' ) ) {
28
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
29
- }
30
-
31
- return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
32
-
33
- }
34
-
35
- }
36
-
37
- if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
38
-
39
- register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
40
- function pys_free_plugin_activated() {
41
-
42
- if ( pys_is_pixelyoursite_pro_active() ) {
43
- wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
44
- 'back_link' => true,
45
- ) );
46
- }
47
-
48
- $options = get_option( 'pixel_your_site' );
49
-
50
- if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
51
-
52
- require_once 'inc/general.php';
53
- pys_initialize_settings();
54
-
55
- }
56
-
57
- }
58
-
59
- }
60
-
61
- if ( ! pys_is_pixelyoursite_pro_active() ) {
62
- require_once 'inc/general.php';
63
- }
 
 
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.0.9
9
+ License: GPLv3
10
+ WC requires at least: 2.6.0
11
+ WC tested up to: 3.2.6
12
+ */
13
+
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit; // Exit if accessed directly.
16
+ }
17
+
18
+ define( 'PYS_FREE_VERSION', '5.0.9' );
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,1511 +1,1534 @@
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 = intval( $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
-
798
- if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
799
- return;
800
- }
801
-
802
- pys_add_event( 'Search', array(
803
- 'search_string' => $_REQUEST['s']
804
- ) );
805
-
806
- }
807
-
808
- }
809
-
810
- if( ! function_exists( 'pys_standard_events' ) ) {
811
-
812
- function pys_standard_events() {
813
- global $pys_custom_events;
814
-
815
- $std_events = get_option( 'pixel_your_site_std_events', array() );
816
-
817
- if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
818
- return;
819
- }
820
-
821
- foreach ( $std_events as $event ) {
822
-
823
- // skip wrong events
824
- if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
825
- continue;
826
- }
827
-
828
- // skip if current page does not match URL filter
829
- if ( pys_match_url( $event['pageurl'] ) == false ) {
830
- continue;
831
- }
832
-
833
- if ( $event['eventtype'] == 'CustomCode' ) {
834
-
835
- $custom_code = $event['code'];
836
- $custom_code = stripcslashes( $custom_code );
837
- $custom_code = trim( $custom_code );
838
-
839
- // add custom code to global custom events array
840
- $pys_custom_events[] = $custom_code;
841
-
842
- } else {
843
-
844
- $type = $event['eventtype'];
845
- $params = pys_clean_system_event_params( $event );
846
-
847
- pys_add_event( $type, $params );
848
-
849
- }
850
-
851
- }
852
-
853
- }
854
-
855
- }
856
-
857
- if( !function_exists( 'pys_pixel_init_event' ) ) {
858
-
859
- function pys_pixel_init_event() {
860
- global $pys_events;
861
-
862
- $pys_events[] = array(
863
- 'type' => 'init',
864
- 'name' => pys_get_option( 'general', 'pixel_id' ),
865
- 'params' => pys_pixel_init_params()
866
- );
867
-
868
- }
869
-
870
- }
871
-
872
- if( ! function_exists( 'pys_output_noscript_code' ) ) {
873
-
874
- function pys_output_noscript_code() {
875
- global $pys_events;
876
-
877
- if( empty( $pys_events ) ) {
878
- return;
879
- }
880
-
881
- foreach( $pys_events as $event ) {
882
-
883
- $args = array();
884
-
885
- if( $event['type'] == 'init' ) {
886
- continue;
887
- }
888
-
889
- $args['id'] = pys_get_option( 'general', 'pixel_id' );
890
- $args['ev'] = $event['name'];
891
- $args['noscript'] = 1;
892
-
893
- foreach ( $event['params'] as $param => $value ) {
894
- @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
895
- }
896
-
897
- $src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
898
-
899
- // note: ALT tag used to pass ADA compliance
900
- // @see: issue #63 for details
901
-
902
- echo "<noscript><img height='1' width='1' style='display: none;' src='{$src_attr}' alt='facebook_pixel'></noscript>";
903
-
904
- }
905
-
906
- }
907
-
908
- }
909
-
910
- if( ! function_exists( 'pys_output_js_events_code' ) ) {
911
-
912
- function pys_output_js_events_code() {
913
- global $pys_events;
914
-
915
- // allow external plugins modify events
916
- $pys_events = apply_filters( 'pys_prepared_events', $pys_events );
917
-
918
- if( empty( $pys_events ) ) {
919
- return;
920
- }
921
-
922
- wp_localize_script( 'pys-public', 'pys_events', $pys_events );
923
-
924
- }
925
-
926
- }
927
-
928
- if( ! function_exists( 'pys_output_custom_events_code' ) ) {
929
-
930
- function pys_output_custom_events_code() {
931
- global $pys_custom_events;
932
-
933
- if( empty( $pys_custom_events ) ) {
934
- return;
935
- }
936
-
937
- wp_localize_script( 'pys-public', 'pys_customEvents', $pys_custom_events );
938
-
939
- }
940
-
941
- }
942
-
943
- if( !function_exists( 'pys_clean_system_event_params' ) ) {
944
-
945
- function pys_clean_system_event_params( $params ) {
946
-
947
- // remove unused params
948
- unset( $params['pageurl'] );
949
- unset( $params['eventtype'] );
950
- unset( $params['code'] );
951
- unset( $params['trigger_type'] ); // pro
952
- unset( $params['custom_currency'] ); // pro
953
- unset( $params['url'] ); // pro
954
- unset( $params['css'] ); // pro
955
- unset( $params['custom_name'] ); // custom events
956
- unset( $params['scroll_pos'] ); // pro
957
- unset( $params['url_filter'] ); // pro - dynamic events
958
-
959
- return $params;
960
-
961
- }
962
-
963
- }
964
-
965
- if( !function_exists( 'pys_get_woo_checkout_params' ) ) {
966
-
967
- function pys_get_woo_checkout_params( $additional_params_enabled ) {
968
- global $woocommerce;
969
-
970
- // set defaults params
971
- $params = array();
972
- $params['content_type'] = 'product';
973
-
974
- $ids = array(); // cart items ids or sku
975
- $names = ''; // cart items names
976
- $categories = ''; // cart items categories
977
-
978
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
979
-
980
- $product_id = pys_get_woo_cart_item_product_id( $item );
981
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
982
-
983
- // content_name, category_name for each cart item
984
- if ( $additional_params_enabled ) {
985
-
986
- $temp = array();
987
- pys_get_additional_woo_params( $product_id, $temp );
988
-
989
- $names .= isset( $temp['content_name'] ) ? $temp['content_name'] . ' ' : null;
990
- $categories .= isset( $temp['category_name'] ) ? $temp['category_name'] . ' ' : null;
991
-
992
- }
993
-
994
- }
995
-
996
- if ( $additional_params_enabled ) {
997
- $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
998
- }
999
-
1000
- $params['content_ids'] = json_encode( $ids );
1001
-
1002
- if ( ! empty( $names ) ) {
1003
- $params['content_name'] = $names;
1004
- }
1005
-
1006
- if ( ! empty( $categories ) ) {
1007
- $params['category_name'] = $categories;
1008
- }
1009
-
1010
- return $params;
1011
-
1012
- }
1013
-
1014
- }
1015
-
1016
- if( !function_exists( 'pys_get_default_options' ) ) {
1017
-
1018
- function pys_get_default_options() {
1019
-
1020
- $options = array();
1021
-
1022
- $options['general']['pixel_id'] = '';
1023
- $options['general']['enabled'] = 0;
1024
- $options['general']['add_traffic_source'] = 1;
1025
- $options['general']['enable_advance_matching'] = 1;
1026
- $options['general']['in_footer'] = 0;
1027
-
1028
- $options['general']['general_event_enabled'] = 1;
1029
- $options['general']['general_event_name'] = 'GeneralEvent';
1030
- $options['general']['general_event_on_posts_enabled'] = 1;
1031
- $options['general']['general_event_on_pages_enabled'] = 1;
1032
- $options['general']['general_event_on_tax_enabled'] = 1;
1033
- $options['general']['general_event_on_woo_enabled'] = 0;
1034
- $options['general']['general_event_on_edd_enabled'] = 0;
1035
- $options['general']['general_event_add_tags'] = 0;
1036
-
1037
- $options['general']['timeonpage_enabled'] = 1;
1038
-
1039
- $options['general']['search_event_enabled'] = 1;
1040
-
1041
- $options['std']['enabled'] = 0;
1042
-
1043
- $options['dyn']['enabled'] = 0;
1044
- $options['dyn']['enabled_on_content'] = 0;
1045
- $options['dyn']['enabled_on_widget'] = 0;
1046
-
1047
- $options['woo']['enabled'] = pys_is_woocommerce_active() ? 1 : 0;
1048
-
1049
- $options['woo']['content_id'] = 'id';
1050
- $options['woo']['variation_id'] = 'variation';
1051
-
1052
- $options['woo']['enable_additional_params'] = 1;
1053
- $options['woo']['enable_tags'] = 1;
1054
- $options['woo']['tax'] = 'incl';
1055
-
1056
- $options['woo']['on_view_content'] = 1;
1057
- $options['woo']['enable_view_content_value'] = 1;
1058
- $options['woo']['view_content_value_option'] = 'price';
1059
- $options['woo']['view_content_percent_value'] = '';
1060
- $options['woo']['view_content_global_value'] = '';
1061
-
1062
- $options['woo']['on_add_to_cart_btn'] = 1;
1063
- $options['woo']['on_add_to_cart_page'] = 0;
1064
- $options['woo']['on_add_to_cart_checkout'] = 0;
1065
- $options['woo']['enable_add_to_cart_value'] = 1;
1066
- $options['woo']['add_to_cart_value_option'] = 'price';
1067
- $options['woo']['add_to_cart_percent_value'] = '';
1068
- $options['woo']['add_to_cart_global_value'] = '';
1069
-
1070
- $options['woo']['on_checkout_page'] = 1;
1071
- $options['woo']['enable_checkout_value'] = 1;
1072
- $options['woo']['checkout_value_option'] = 'price';
1073
- $options['woo']['checkout_percent_value'] = '';
1074
- $options['woo']['checkout_global_value'] = '';
1075
-
1076
- $options['woo']['on_thank_you_page'] = 1;
1077
- $options['woo']['enable_purchase_value'] = 1;
1078
- $options['woo']['purchase_fire_once'] = 1;
1079
- $options['woo']['purchase_transport'] = 'included';
1080
- $options['woo']['purchase_value_option'] = 'total';
1081
- $options['woo']['purchase_percent_value'] = '';
1082
- $options['woo']['purchase_global_value'] = '';
1083
-
1084
- $options['woo']['purchase_add_address'] = 1;
1085
- $options['woo']['purchase_add_payment_method'] = 1;
1086
- $options['woo']['purchase_add_shipping_method'] = 1;
1087
- $options['woo']['purchase_add_coupons'] = 1;
1088
-
1089
- $options['woo']['enable_aff_event'] = 0;
1090
- $options['woo']['aff_event'] = 'predefined';
1091
- $options['woo']['aff_predefined_value'] = 'Lead';
1092
- $options['woo']['aff_custom_value'] = '';
1093
- $options['woo']['aff_value_option'] = 'none';
1094
- $options['woo']['aff_global_value'] = '';
1095
-
1096
- $options['woo']['enable_paypal_event'] = 0;
1097
- $options['woo']['pp_event'] = 'predefined';
1098
- $options['woo']['pp_predefined_value'] = 'InitiatePayment';
1099
- $options['woo']['pp_custom_value'] = '';
1100
- $options['woo']['pp_value_option'] = 'none';
1101
- $options['woo']['pp_global_value'] = '';
1102
-
1103
- /**
1104
- * Easy Digital Downloads
1105
- */
1106
-
1107
- $options['edd']['enabled'] = pys_is_edd_active() ? 1 : 0;
1108
-
1109
- $options['edd']['content_id'] = 'id';
1110
- $options['edd']['enable_additional_params'] = 1;
1111
- $options['edd']['enable_tags'] = 1;
1112
- $options['edd']['tax'] = 'incl';
1113
-
1114
- $options['edd']['on_view_content'] = 1;
1115
- $options['edd']['on_view_content_delay'] = null;
1116
- $options['edd']['enable_view_content_value'] = 1;
1117
- $options['edd']['view_content_value_option'] = 'price';
1118
- $options['edd']['view_content_percent_value'] = null;
1119
- $options['edd']['view_content_global_value'] = null;
1120
-
1121
- $options['edd']['on_add_to_cart_btn'] = 1;
1122
- $options['edd']['on_add_to_cart_checkout'] = 0;
1123
- $options['edd']['enable_add_to_cart_value'] = 1;
1124
- $options['edd']['add_to_cart_value_option'] = 'price';
1125
- $options['edd']['add_to_cart_percent_value'] = null;
1126
- $options['edd']['add_to_cart_global_value'] = null;
1127
-
1128
- $options['edd']['on_checkout_page'] = 1;
1129
- $options['edd']['enable_checkout_value'] = 1;
1130
- $options['edd']['checkout_value_option'] = 'price';
1131
- $options['edd']['checkout_percent_value'] = null;
1132
- $options['edd']['checkout_global_value'] = null;
1133
-
1134
- $options['edd']['on_success_page'] = 1;
1135
- $options['edd']['enable_purchase_value'] = 1;
1136
- $options['edd']['purchase_fire_once'] = 1;
1137
- $options['edd']['purchase_value_option'] = 'total';
1138
- $options['edd']['purchase_percent_value'] = null;
1139
- $options['edd']['purchase_global_value'] = null;
1140
-
1141
- $options['edd']['purchase_add_address'] = true;
1142
- $options['edd']['purchase_add_payment_method'] = true;
1143
- $options['edd']['purchase_add_coupons'] = true;
1144
-
1145
- return apply_filters( 'pys_fb_pixel_setting_defaults', $options );
1146
-
1147
- }
1148
-
1149
- }
1150
-
1151
- if( ! function_exists( 'pys_get_custom_params' ) ) {
1152
-
1153
- /**
1154
- * Extract non-system params array
1155
- */
1156
- function pys_get_custom_params( $event ) {
1157
-
1158
- if( !is_array( $event ) || empty( $event ) ) {
1159
- return array();
1160
- }
1161
-
1162
- $system_params = array(
1163
- 'trigger_type',
1164
- 'url_filter',
1165
- 'url',
1166
- 'css',
1167
- 'pageurl',
1168
- 'eventtype',
1169
- 'value',
1170
- 'currency',
1171
- 'custom_currency',
1172
- 'content_name',
1173
- 'content_ids',
1174
- 'content_type',
1175
- 'content_category',
1176
- 'num_items',
1177
- 'order_id',
1178
- 'search_string',
1179
- 'status',
1180
- 'code',
1181
- 'custom_name',
1182
- 'scroll_pos'
1183
- );
1184
-
1185
- $custom_params = array();
1186
- foreach( $event as $param => $value ) {
1187
-
1188
- // skip standard params
1189
- if( in_array( $param, $system_params ) ) {
1190
- continue;
1191
- }
1192
-
1193
- $custom_params[ $param ] = $value;
1194
-
1195
- }
1196
-
1197
-
1198
- return $custom_params;
1199
-
1200
- }
1201
-
1202
- }
1203
-
1204
- if( ! function_exists( 'pys_is_standard_event' ) ) {
1205
-
1206
- function pys_is_standard_event( $eventtype ) {
1207
-
1208
- $std_events = array(
1209
- 'PageView',
1210
- 'ViewContent',
1211
- 'Search',
1212
- 'AddToCart',
1213
- 'AddToWishlist',
1214
- 'InitiateCheckout',
1215
- 'AddPaymentInfo',
1216
- 'Purchase',
1217
- 'Lead'
1218
- );
1219
-
1220
- return in_array( $eventtype, $std_events );
1221
-
1222
- }
1223
-
1224
- }
1225
-
1226
- if( ! function_exists( 'pys_pixel_init_params' ) ) {
1227
-
1228
- /**
1229
- * Add extra params to FB init call.
1230
- */
1231
- function pys_pixel_init_params() {
1232
-
1233
- $params = array();
1234
- $params = apply_filters( 'pys_pixel_init_params', $params );
1235
-
1236
- $sanitized = array();
1237
-
1238
- // sanitize params
1239
- foreach ( $params as $name => $value ) {
1240
-
1241
- if ( empty( $value ) ) {
1242
- continue;
1243
- }
1244
-
1245
- $key = esc_js( $name );
1246
- $sanitized[ $key ] = $value;
1247
-
1248
- }
1249
-
1250
- return $sanitized;
1251
-
1252
- }
1253
-
1254
- }
1255
-
1256
- if( ! function_exists( 'pys_woocommerce_events' ) ) {
1257
-
1258
- function pys_woocommerce_events() {
1259
-
1260
- if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
1261
- return;
1262
- }
1263
-
1264
- pys_get_woo_code();
1265
-
1266
- // WooCommerce non-ajax AddToCart Event handler
1267
- if ( pys_get_option( 'woo', 'on_add_to_cart_btn' ) && isset( $_REQUEST['add-to-cart'] ) ) {
1268
-
1269
- if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $_REQUEST['variation_id'] ) ) {
1270
- $product_id = $_REQUEST['variation_id'];
1271
- } else {
1272
- $product_id = isset( $_REQUEST['add-to-cart'] ) ? $_REQUEST['add-to-cart'] : null;
1273
- }
1274
-
1275
- $params = pys_get_woo_ajax_addtocart_params( $product_id );
1276
-
1277
- pys_add_event( 'AddToCart', $params );
1278
-
1279
- }
1280
-
1281
- }
1282
-
1283
- }
1284
-
1285
- if( ! function_exists( 'pys_output_woo_ajax_events_code' ) ) {
1286
-
1287
- function pys_output_woo_ajax_events_code() {
1288
- global $pys_woo_ajax_events;
1289
-
1290
- if( empty( $pys_woo_ajax_events ) ) {
1291
- return;
1292
- }
1293
-
1294
- $events = array();
1295
-
1296
- foreach ( $pys_woo_ajax_events as $id => $event ) {
1297
-
1298
- $params = pys_clean_system_event_params( $event['params'] );
1299
-
1300
- // sanitize params
1301
- $sanitized = array();
1302
- foreach ( $params as $name => $value ) {
1303
-
1304
- // skip empty but not zero values
1305
- if ( empty( $value ) && ! is_numeric( $value ) ) {
1306
- continue;
1307
- }
1308
-
1309
- $key = esc_js( $name );
1310
- $sanitized[ $key ] = $value;
1311
-
1312
- }
1313
-
1314
- $name = $event['name'];
1315
-
1316
- $events[ $id ] = array(
1317
- 'type' => pys_is_standard_event( $name ) ? 'track' : 'trackCustom',
1318
- 'name' => $name,
1319
- 'params' => $sanitized
1320
- );
1321
-
1322
- }
1323
-
1324
- ?>
1325
-
1326
- <script type="text/javascript">
1327
- /* <![CDATA[ */
1328
- var pys_woo_ajax_events = <?php echo json_encode( $events ); ?>;
1329
- /* ]]> */
1330
- </script>
1331
-
1332
- <?php
1333
-
1334
- }
1335
-
1336
- }
1337
-
1338
- if( ! function_exists( 'pys_output_options' ) ) {
1339
-
1340
- function pys_output_options() {
1341
-
1342
- $options = array(
1343
- 'site_url' => get_site_url(),
1344
- 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1345
- );
1346
-
1347
- wp_localize_script( 'pys-public', 'pys_options', $options );
1348
-
1349
- }
1350
-
1351
- }
1352
-
1353
- if( ! function_exists( 'pys_head_comments' ) ) {
1354
-
1355
- function pys_head_comments() {
1356
-
1357
- if( defined( 'PYS_PRO_VERSION' ) ) {
1358
- $version = "PRO v" . PYS_PRO_VERSION;
1359
- } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1360
- $version = "FREE v" . PYS_FREE_VERSION;
1361
- } else {
1362
- $version = null;
1363
- }
1364
-
1365
- ?>
1366
-
1367
- <!-- 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. -->
1368
-
1369
- <?php
1370
- }
1371
-
1372
- }
1373
-
1374
- if( ! function_exists( 'pys_render_event_code' ) ) {
1375
-
1376
- /**
1377
- * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1378
- */
1379
- function pys_render_event_code( $event_name, $params ) {
1380
-
1381
- $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1382
-
1383
- $params = pys_clean_system_event_params( $params );
1384
-
1385
- $event_params = '';
1386
- foreach( $params as $name => $value ) {
1387
-
1388
- if( empty( $value ) && $value !== "0" ) {
1389
- continue;
1390
- }
1391
-
1392
- $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1393
-
1394
- }
1395
-
1396
- $event_params = ltrim( $event_params );
1397
- $event_params = rtrim( $event_params, "," );
1398
-
1399
- return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1400
-
1401
- }
1402
-
1403
- }
1404
-
1405
- if( !function_exists( 'pys_add_domain_param' ) ) {
1406
-
1407
- function pys_add_domain_param( $params, $event ) {
1408
-
1409
- // get home URL without protocol
1410
- $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1411
- return $params;
1412
-
1413
- }
1414
-
1415
- }
1416
-
1417
- if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
1418
-
1419
- function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
1420
-
1421
- // get WP_Post object
1422
- if ( is_numeric( $post ) ) {
1423
- $id = absint( $post );
1424
- $_post = get_post( $id );
1425
- } elseif ( $post instanceof WC_Product ) {
1426
- $_post = $post->post;
1427
- } elseif ( isset( $post->ID ) ) {
1428
- $_post = $post;
1429
- } else {
1430
- return;
1431
- }
1432
-
1433
- $params['content_name'] = $_post->post_title;
1434
-
1435
- $terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
1436
- if ( $terms ) {
1437
- $params['category_name'] = $terms;
1438
- }
1439
-
1440
- }
1441
-
1442
- }
1443
-
1444
- if ( ! function_exists( 'pys_get_object_tags' ) ) {
1445
-
1446
- /**
1447
- * @param int|WP_Post $post Post ID or object
1448
- * @param string $taxonomy Taxonomy name
1449
- *
1450
- * @return array Array of terms titles on success or empty array
1451
- */
1452
- function pys_get_object_tags( $post, $taxonomy ) {
1453
-
1454
- $tags = array();
1455
- $terms = get_the_terms( $post, $taxonomy );
1456
-
1457
- if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1458
-
1459
- foreach ( $terms as $term ) {
1460
- $tags[] = html_entity_decode( $term->name );
1461
- }
1462
-
1463
- }
1464
-
1465
- return $tags;
1466
-
1467
- }
1468
-
1469
- }
1470
-
1471
- if ( ! function_exists( 'pys_delete_events' ) ) {
1472
-
1473
- function pys_delete_events( $events_ids, $events_type ) {
1474
-
1475
- if ( $events_type == 'standard' ) {
1476
- $option_name = 'pixel_your_site_std_events';
1477
- } else {
1478
- $option_name = 'pixel_your_site_dyn_events';
1479
- }
1480
-
1481
- $events = (array) get_option( $option_name );
1482
-
1483
- if ( empty( $events ) ) {
1484
- return;
1485
- }
1486
-
1487
- foreach ( $events_ids as $id ) {
1488
- unset( $events[ $id ] );
1489
- }
1490
-
1491
- update_option( $option_name, $events );
1492
-
1493
- }
1494
-
1495
- }
1496
-
1497
- if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
1498
-
1499
- function pys_is_wc_version_gte( $version ) {
1500
-
1501
- if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
1502
- return version_compare( WC_VERSION, $version, '>=' );
1503
- } else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
1504
- return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
1505
- } else {
1506
- return false;
1507
- }
1508
-
1509
- }
1510
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1511
  }
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'] ) ? $_REQUEST['add-to-cart'] : null;
1296
+ }
1297
+
1298
+ $params = pys_get_woo_ajax_addtocart_params( $product_id );
1299
+
1300
+ pys_add_event( 'AddToCart', $params );
1301
+
1302
+ }
1303
+
1304
+ }
1305
+
1306
+ }
1307
+
1308
+ if( ! function_exists( 'pys_output_woo_ajax_events_code' ) ) {
1309
+
1310
+ function pys_output_woo_ajax_events_code() {
1311
+ global $pys_woo_ajax_events;
1312
+
1313
+ if( empty( $pys_woo_ajax_events ) ) {
1314
+ return;
1315
+ }
1316
+
1317
+ $events = array();
1318
+
1319
+ foreach ( $pys_woo_ajax_events as $id => $event ) {
1320
+
1321
+ $params = pys_clean_system_event_params( $event['params'] );
1322
+
1323
+ // sanitize params
1324
+ $sanitized = array();
1325
+ foreach ( $params as $name => $value ) {
1326
+
1327
+ // skip empty but not zero values
1328
+ if ( empty( $value ) && ! is_numeric( $value ) ) {
1329
+ continue;
1330
+ }
1331
+
1332
+ $key = esc_js( $name );
1333
+ $sanitized[ $key ] = $value;
1334
+
1335
+ }
1336
+
1337
+ $name = $event['name'];
1338
+
1339
+ $events[ $id ] = array(
1340
+ 'type' => pys_is_standard_event( $name ) ? 'track' : 'trackCustom',
1341
+ 'name' => $name,
1342
+ 'params' => $sanitized
1343
+ );
1344
+
1345
+ }
1346
+
1347
+ ?>
1348
+
1349
+ <script type="text/javascript">
1350
+ /* <![CDATA[ */
1351
+ var pys_woo_ajax_events = <?php echo json_encode( $events ); ?>;
1352
+ /* ]]> */
1353
+ </script>
1354
+
1355
+ <?php
1356
+
1357
+ }
1358
+
1359
+ }
1360
+
1361
+ if( ! function_exists( 'pys_output_options' ) ) {
1362
+
1363
+ function pys_output_options() {
1364
+
1365
+ $options = array(
1366
+ 'site_url' => get_site_url(),
1367
+ 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1368
+ );
1369
+
1370
+ wp_localize_script( 'pys-public', 'pys_options', $options );
1371
+
1372
+ }
1373
+
1374
+ }
1375
+
1376
+ if( ! function_exists( 'pys_head_comments' ) ) {
1377
+
1378
+ function pys_head_comments() {
1379
+
1380
+ if( defined( 'PYS_PRO_VERSION' ) ) {
1381
+ $version = "PRO v" . PYS_PRO_VERSION;
1382
+ } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1383
+ $version = "FREE v" . PYS_FREE_VERSION;
1384
+ } else {
1385
+ $version = null;
1386
+ }
1387
+
1388
+ ?>
1389
+
1390
+ <!-- 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. -->
1391
+
1392
+ <?php
1393
+ }
1394
+
1395
+ }
1396
+
1397
+ if( ! function_exists( 'pys_render_event_code' ) ) {
1398
+
1399
+ /**
1400
+ * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1401
+ */
1402
+ function pys_render_event_code( $event_name, $params ) {
1403
+
1404
+ $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1405
+
1406
+ $params = pys_clean_system_event_params( $params );
1407
+
1408
+ $event_params = '';
1409
+ foreach( $params as $name => $value ) {
1410
+
1411
+ if( empty( $value ) && $value !== "0" ) {
1412
+ continue;
1413
+ }
1414
+
1415
+ $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1416
+
1417
+ }
1418
+
1419
+ $event_params = ltrim( $event_params );
1420
+ $event_params = rtrim( $event_params, "," );
1421
+
1422
+ return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1423
+
1424
+ }
1425
+
1426
+ }
1427
+
1428
+ if( !function_exists( 'pys_add_domain_param' ) ) {
1429
+
1430
+ function pys_add_domain_param( $params, $event ) {
1431
+
1432
+ // get home URL without protocol
1433
+ $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1434
+ return $params;
1435
+
1436
+ }
1437
+
1438
+ }
1439
+
1440
+ if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
1441
+
1442
+ function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
1443
+
1444
+ // get WP_Post object
1445
+ if ( is_numeric( $post ) ) {
1446
+ $id = absint( $post );
1447
+ $_post = get_post( $id );
1448
+ } elseif ( $post instanceof WC_Product ) {
1449
+ $_post = $post->post;
1450
+ } elseif ( isset( $post->ID ) ) {
1451
+ $_post = $post;
1452
+ } else {
1453
+ return;
1454
+ }
1455
+
1456
+ $params['content_name'] = $_post->post_title;
1457
+
1458
+ $terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
1459
+ if ( $terms ) {
1460
+ $params['category_name'] = $terms;
1461
+ }
1462
+
1463
+ }
1464
+
1465
+ }
1466
+
1467
+ if ( ! function_exists( 'pys_get_object_tags' ) ) {
1468
+
1469
+ /**
1470
+ * @param int|WP_Post $post Post ID or object
1471
+ * @param string $taxonomy Taxonomy name
1472
+ *
1473
+ * @return array Array of terms titles on success or empty array
1474
+ */
1475
+ function pys_get_object_tags( $post, $taxonomy ) {
1476
+
1477
+ $tags = array();
1478
+ $terms = get_the_terms( $post, $taxonomy );
1479
+
1480
+ if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1481
+
1482
+ foreach ( $terms as $term ) {
1483
+ $tags[] = html_entity_decode( $term->name );
1484
+ }
1485
+
1486
+ }
1487
+
1488
+ return $tags;
1489
+
1490
+ }
1491
+
1492
+ }
1493
+
1494
+ if ( ! function_exists( 'pys_delete_events' ) ) {
1495
+
1496
+ function pys_delete_events( $events_ids, $events_type ) {
1497
+
1498
+ if ( $events_type == 'standard' ) {
1499
+ $option_name = 'pixel_your_site_std_events';
1500
+ } else {
1501
+ $option_name = 'pixel_your_site_dyn_events';
1502
+ }
1503
+
1504
+ $events = (array) get_option( $option_name );
1505
+
1506
+ if ( empty( $events ) ) {
1507
+ return;
1508
+ }
1509
+
1510
+ foreach ( $events_ids as $id ) {
1511
+ unset( $events[ $id ] );
1512
+ }
1513
+
1514
+ update_option( $option_name, $events );
1515
+
1516
+ }
1517
+
1518
+ }
1519
+
1520
+ if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
1521
+
1522
+ function pys_is_wc_version_gte( $version ) {
1523
+
1524
+ if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
1525
+ return version_compare( WC_VERSION, $version, '>=' );
1526
+ } else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
1527
+ return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
1528
+ } else {
1529
+ return false;
1530
+ }
1531
+
1532
+ }
1533
+
1534
  }
inc/core-edd.php CHANGED
@@ -1,199 +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
-
11
- if ( pys_get_option( 'edd', 'enabled' ) == false || pys_is_edd_active() == false ) {
12
- return;
13
- }
14
-
15
- global $post;
16
-
17
- // set defaults params
18
- $params = array();
19
- $params['content_type'] = 'product';
20
-
21
- // ViewContent Event
22
- if ( pys_get_option( 'edd', 'on_view_content' ) && is_singular( array( 'download' ) ) ) {
23
-
24
- $params['content_ids'] = "['" . pys_get_edd_content_id( $post->ID ) . "']";
25
-
26
- // currency, value
27
- if ( pys_get_option( 'edd', 'enable_view_content_value' ) ) {
28
-
29
- $params['value'] = pys_get_option( 'edd', 'view_content_global_value' );
30
- $params['currency'] = edd_get_currency();
31
-
32
- }
33
-
34
- pys_add_event( 'ViewContent', $params, 0 );
35
-
36
- return;
37
-
38
- }
39
-
40
- /**
41
- * AddToCart Event (button)
42
- *
43
- * @see pys_edd_purchase_link_args()
44
- */
45
-
46
- // AddToCart on Checkout page
47
- if ( pys_get_option( 'edd', 'on_add_to_cart_checkout' ) && edd_is_checkout() ) {
48
-
49
- $ids = array();
50
-
51
- foreach ( edd_get_cart_contents() as $cart_item ) {
52
-
53
- $download_id = intval( $cart_item['id'] );
54
- $ids[] = pys_get_edd_content_id( $download_id );
55
-
56
- }
57
-
58
- $params['content_ids'] = "'[" . implode( "','", $ids ) . "']";
59
-
60
- // currency, value
61
- if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
62
-
63
- $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
64
- $params['currency'] = edd_get_currency();
65
-
66
- }
67
-
68
- pys_add_event( 'AddToCart', $params );
69
-
70
- }
71
-
72
- // InitiateCheckout Event
73
- if ( pys_get_option( 'edd', 'on_checkout_page' ) && edd_is_checkout() ) {
74
-
75
- $ids = array();
76
-
77
- foreach ( edd_get_cart_contents() as $cart_item ) {
78
-
79
- $download_id = intval( $cart_item['id'] );
80
- $ids[] = pys_get_edd_content_id( $download_id );
81
-
82
- }
83
-
84
- $params['content_ids'] = "'[" . implode( "','", $ids ) . "']";
85
-
86
- // currency, value
87
- if ( pys_get_option( 'edd', 'enable_checkout_value' ) ) {
88
-
89
- $params['value'] = pys_get_option( 'edd', 'checkout_global_value' );
90
- $params['currency'] = edd_get_currency();
91
-
92
- }
93
-
94
- pys_add_event( 'InitiateCheckout', $params );
95
-
96
- return;
97
-
98
- }
99
-
100
- // Purchase Event
101
- if ( pys_get_option( 'edd', 'on_success_page' ) && edd_is_success_page() ) {
102
-
103
- ## skip payment confirmation page
104
- if( isset( $_GET['payment-confirmation'] ) ) {
105
- return;
106
- }
107
-
108
- global $edd_receipt_args;
109
-
110
- $session = edd_get_purchase_session();
111
- if ( isset( $_GET['payment_key'] ) ) {
112
- $payment_key = urldecode( $_GET['payment_key'] );
113
- } else if ( $session ) {
114
- $payment_key = $session['purchase_key'];
115
- } elseif ( $edd_receipt_args['payment_key'] ) {
116
- $payment_key = $edd_receipt_args['payment_key'];
117
- }
118
-
119
- if ( ! isset( $payment_key ) ) {
120
- return;
121
- }
122
-
123
- $payment_id = edd_get_purchase_id_by_key( $payment_key );
124
- $user_can_view = edd_can_view_receipt( $payment_key );
125
-
126
- if ( ! $user_can_view && ! empty( $payment_key ) && ! is_user_logged_in() && ! edd_is_guest_payment( $payment_id ) ) {
127
- return;
128
- }
129
-
130
- $cart = edd_get_payment_meta_cart_details( $payment_id, true );
131
- $status = edd_get_payment_status( $payment_id, true );
132
-
133
- ## pending payment status used because we can't fire event on IPN
134
- if( strtolower( $status ) != 'complete' && strtolower( $status ) != 'pending' ) {
135
- return;
136
- }
137
-
138
- $ids = array();
139
-
140
- foreach ( $cart as $cart_item ) {
141
-
142
- $download_id = intval( $cart_item['id'] );
143
- $ids[] = pys_get_edd_content_id( $download_id );
144
-
145
- }
146
-
147
- $params['content_ids'] = "['" . implode( "','", $ids ) . "']";
148
-
149
- // currency, value
150
- if ( pys_get_option( 'edd', 'enable_purchase_value' ) ) {
151
-
152
- $params['value'] = pys_get_option( 'edd', 'purchase_global_value' );
153
- $params['currency'] = edd_get_currency();
154
-
155
- }
156
-
157
- pys_add_event( 'Purchase', $params );
158
-
159
- return;
160
-
161
- }
162
-
163
- }
164
-
165
- }
166
-
167
- if ( ! function_exists( 'pys_edd_purchase_link_args' ) ) {
168
-
169
- function pys_edd_purchase_link_args( $args = array() ) {
170
- global $pys_edd_ajax_events;
171
-
172
- $download_id = $args['download_id'];
173
- $event_id = uniqid();
174
-
175
- $params = array();
176
- $params['content_type'] = 'product';
177
- $params['content_ids'] = "['" . pys_get_edd_content_id( $download_id ) . "']";
178
-
179
- // currency, value
180
- if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
181
-
182
- $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
183
- $params['currency'] = edd_get_currency();
184
-
185
- }
186
-
187
- $pys_edd_ajax_events[ $event_id ] = array(
188
- 'name' => 'AddToCart',
189
- 'params' => $params
190
- );
191
-
192
- $classes = isset( $args['class'] ) ? $args['class'] : null;
193
- $args['class'] = $classes . " pys-event-id-{$event_id}";
194
-
195
- return $args;
196
-
197
- }
198
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  }
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,557 +1,699 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- if ( ! function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
8
-
9
- function pys_get_woo_ajax_addtocart_params( $product_id ) {
10
-
11
- $params = array();
12
- $params['content_type'] = 'product';
13
- $params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
14
-
15
- // currency, value
16
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
17
-
18
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
19
- switch ( $option ) {
20
- case 'global':
21
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
22
- break;
23
-
24
- case 'price':
25
- $value = pys_get_product_price( $product_id );
26
- break;
27
-
28
- default:
29
- $value = null;
30
- }
31
-
32
- $params['value'] = $value;
33
- $params['currency'] = get_woocommerce_currency();
34
-
35
- }
36
-
37
- return $params;
38
-
39
- }
40
-
41
- }
42
-
43
- if ( ! function_exists( 'pys_get_post_tags' ) ) {
44
-
45
- /**
46
- * Return array of product tags.
47
- * PRO only.
48
- */
49
- function pys_get_post_tags( $post_id ) {
50
-
51
- return array(); // PRO feature
52
-
53
- }
54
-
55
- }
56
-
57
- if ( ! function_exists( 'pys_get_woo_code' ) ) {
58
-
59
- /**
60
- * Build WooCommerce related events code.
61
- * Function adds evaluated event params to global array.
62
- */
63
- function pys_get_woo_code() {
64
- global $post, $woocommerce;
65
-
66
- // set defaults params
67
- $params = array();
68
- $params['content_type'] = 'product';
69
-
70
- // ViewContent Event
71
- if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
72
-
73
- $product = wc_get_product( $post->ID );
74
-
75
- $params['content_ids'] = json_encode( pys_get_product_content_id( $post->ID ) );
76
-
77
- if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
78
- $params['content_type'] = 'product_group';
79
- } else {
80
- $params['content_type'] = 'product';
81
- }
82
-
83
- // @since 5.0.6
84
- $params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
85
- $product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
86
-
87
- // currency, value
88
- if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
89
-
90
- $option = pys_get_option( 'woo', 'view_content_value_option' );
91
- switch ( $option ) {
92
- case 'global':
93
- $value = pys_get_option( 'woo', 'view_content_global_value' );
94
- break;
95
-
96
- case 'price':
97
- $value = pys_get_product_price( $post );
98
- break;
99
-
100
- default:
101
- $value = null;
102
- }
103
-
104
- $params['value'] = $value;
105
- $params['currency'] = get_woocommerce_currency();
106
-
107
- }
108
-
109
- pys_add_event( 'ViewContent', $params );
110
-
111
- return;
112
-
113
- }
114
-
115
- // AddToCart Cart Page Event
116
- if ( pys_get_option( 'woo', 'on_add_to_cart_page' ) && is_cart() ) {
117
-
118
- $ids = array(); // cart items ids or sku
119
-
120
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
121
-
122
- $product_id = pys_get_woo_cart_item_product_id( $item );
123
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
124
-
125
- }
126
-
127
- $params['content_ids'] = json_encode( $ids );
128
-
129
- // currency, value
130
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
131
-
132
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
133
- switch ( $option ) {
134
- case 'global':
135
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
136
- break;
137
-
138
- case 'price':
139
- $value = pys_get_cart_total();
140
- break;
141
-
142
- default:
143
- $value = null;
144
- }
145
-
146
- $params['value'] = $value;
147
- $params['currency'] = get_woocommerce_currency();
148
-
149
- }
150
-
151
- pys_add_event( 'AddToCart', $params );
152
-
153
- return;
154
-
155
- }
156
-
157
- // AddToCart on Checkout page
158
- if ( pys_get_option( 'woo', 'on_add_to_cart_checkout' ) && is_checkout() && ! is_wc_endpoint_url() ) {
159
-
160
- $ids = array(); // cart items ids or sku
161
-
162
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
163
-
164
- $product_id = pys_get_woo_cart_item_product_id( $item );
165
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
166
-
167
- }
168
-
169
- $params['content_ids'] = json_encode( $ids );
170
-
171
- // currency, value
172
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
173
-
174
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
175
- switch ( $option ) {
176
- case 'global':
177
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
178
- break;
179
-
180
- case 'price':
181
- $value = pys_get_cart_total();
182
- break;
183
-
184
- default:
185
- $value = null;
186
- }
187
-
188
- $params['value'] = $value;
189
- $params['currency'] = get_woocommerce_currency();
190
-
191
- }
192
-
193
- pys_add_event( 'AddToCart', $params );
194
-
195
- }
196
-
197
- // Checkout Page Event
198
- if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
199
-
200
- $params = pys_get_woo_checkout_params( false );
201
-
202
- // currency, value
203
- if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
204
-
205
- $option = pys_get_option( 'woo', 'checkout_value_option' );
206
- switch ( $option ) {
207
- case 'global':
208
- $value = pys_get_option( 'woo', 'checkout_global_value' );
209
- break;
210
-
211
- case 'price':
212
- $value = pys_get_cart_total();
213
- break;
214
-
215
- default:
216
- $value = null;
217
- }
218
-
219
- $params['value'] = $value;
220
- $params['currency'] = get_woocommerce_currency();
221
-
222
- }
223
-
224
- pys_add_event( 'InitiateCheckout', $params );
225
-
226
- return;
227
-
228
- }
229
-
230
- // Purchase Event
231
- if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
232
-
233
- $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
234
- $order = new WC_Order( $order_id );
235
- $items = $order->get_items( 'line_item' );
236
-
237
- $ids = array(); // order items ids or sku
238
-
239
- foreach ( $items as $item ) {
240
-
241
- $product_id = pys_get_woo_cart_item_product_id( $item );
242
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
243
-
244
- }
245
-
246
- $params['content_ids'] = json_encode( $ids );
247
-
248
- // currency, value
249
- if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
250
-
251
- $option = pys_get_option( 'woo', 'purchase_value_option' );
252
- switch ( $option ) {
253
- case 'global':
254
- $value = pys_get_option( 'woo', 'purchase_global_value' );
255
- break;
256
-
257
- case 'total':
258
- $value = pys_get_order_total( $order );
259
- break;
260
-
261
- default:
262
- $value = null;
263
- }
264
-
265
- $params['value'] = $value;
266
- $params['currency'] = get_woocommerce_currency();
267
-
268
- }
269
-
270
- pys_add_event( 'Purchase', $params );
271
-
272
- return;
273
-
274
- }
275
-
276
- }
277
-
278
- }
279
-
280
- if ( ! function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
281
-
282
- /**
283
- * Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
284
- *
285
- * @param string $tag
286
- * @param WC_Product $product
287
- *
288
- * @return string
289
- */
290
- function pys_add_code_to_woo_cart_link( $tag, $product ) {
291
- global $pys_woo_ajax_events;
292
-
293
- // do not add code if AJAX is disabled. event will be processed by another function
294
- if ( 'yes' !== get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
295
- return $tag;
296
- }
297
-
298
- if ( false == pys_woo_product_is_type( $product, 'simple' ) ) {
299
- return $tag;
300
- }
301
-
302
- $event_id = uniqid();
303
-
304
- /**
305
- * @since 5.0.1
306
- */
307
- if ( pys_is_wc_version_gte( '2.6' ) ) {
308
- $product_id = $product->get_id();
309
- } else {
310
- $product_id = $product->post->ID;
311
- }
312
-
313
- // common params
314
- $params = array();
315
- $params['content_type'] = 'product';
316
- $params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
317
-
318
- // currency, value
319
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
320
-
321
- $option = pys_get_option( 'woo', 'view_content_value_option' );
322
- switch ( $option ) {
323
- case 'global':
324
- $value = pys_get_option( 'woo', 'view_content_global_value' );
325
- break;
326
-
327
- case 'price':
328
- $value = pys_get_product_price( $product_id );
329
- break;
330
-
331
- default:
332
- $value = null;
333
-
334
- }
335
-
336
- $params['value'] = $value;
337
- $params['currency'] = get_woocommerce_currency();
338
-
339
- }
340
-
341
- $tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true, 'any' );
342
-
343
- $pys_woo_ajax_events[ $event_id ] = array(
344
- 'name' => 'AddToCart',
345
- 'params' => $params
346
- );
347
-
348
- return $tag;
349
-
350
- }
351
-
352
- }
353
-
354
- if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
355
-
356
- /**
357
- * Adds extra params to pixel init code. On Free always returns empty string.
358
- * PRO only.
359
- *
360
- * @see: https://www.facebook.com/help/ipad-app/606443329504150
361
- * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
362
- * @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
363
- *
364
- * @return string
365
- */
366
- function pys_get_additional_matching_code() {
367
-
368
- return ''; // PRO feature
369
-
370
- }
371
-
372
- }
373
-
374
- if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
375
-
376
- /**
377
- * Adds additional post parameters like `content_name` and `category_name`.
378
- * PRO only.
379
- *
380
- * @param $post WP_Post|int
381
- * @param $params array reference to $params array
382
- */
383
- function pys_get_additional_woo_params( $post, &$params ) {
384
-
385
- // PRO only
386
-
387
- }
388
-
389
- }
390
-
391
- if ( ! function_exists( 'pys_general_woo_event' ) ) {
392
-
393
- /**
394
- * Add General event on Woo Product page. PRO only.
395
- *
396
- * @param $post WP_Post|int
397
- * @param $track_tags bool
398
- * @param $delay int
399
- * @param $event_name string
400
- */
401
- function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
402
- // PRO feature
403
- }
404
-
405
- }
406
-
407
- if ( ! function_exists( 'pys_general_edd_event' ) ) {
408
-
409
- /**
410
- * Add General event on EDD Download page. PRO only.
411
- *
412
- * @param $post WP_Post|int
413
- * @param $track_tags bool
414
- * @param $delay int
415
- * @param $event_name string
416
- */
417
- function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
418
- // PRO feature
419
- }
420
-
421
- }
422
-
423
- if ( ! function_exists( 'pys_get_product_price' ) ) {
424
-
425
- /**
426
- * Return product price depends on plugin, product and WooCommerce settings.
427
- *
428
- * @param $product_id
429
- *
430
- * @return null|int Product price
431
- */
432
- function pys_get_product_price( $product_id ) {
433
-
434
- $product = wc_get_product( $product_id );
435
-
436
- /**
437
- * @since 5.0.9
438
- */
439
- if ( false == $product instanceof WC_Product ) {
440
- return 0;
441
- }
442
-
443
- if ( $product->is_taxable() ) {
444
-
445
- /**
446
- * @since 5.0.8
447
- */
448
- if ( pys_is_wc_version_gte( '2.7' ) ) {
449
- $value = wc_get_price_including_tax( $product, $product->get_price() );
450
- } else {
451
- $value = $product->get_price_including_tax( 1, $product->get_price() );
452
- }
453
-
454
- } else {
455
-
456
- /**
457
- * @since 5.0.8
458
- */
459
- if ( pys_is_wc_version_gte( '2.7' ) ) {
460
- $value = wc_get_price_excluding_tax( $product, $product->get_price() );
461
- } else {
462
- $value = $product->get_price_excluding_tax( 1, $product->get_price() );
463
- }
464
-
465
- }
466
-
467
- return $value;
468
-
469
- }
470
-
471
- }
472
-
473
- if ( ! function_exists( 'pys_get_cart_total' ) ) {
474
-
475
- function pys_get_cart_total() {
476
- global $woocommerce;
477
-
478
- return $woocommerce->cart->subtotal;
479
-
480
- }
481
-
482
- }
483
-
484
- if ( ! function_exists( 'pys_get_order_total' ) ) {
485
-
486
- /**
487
- * Calculates order 'value' param depends on WooCommerce and PYS settings
488
- */
489
- function pys_get_order_total( $order ) {
490
-
491
- //wc_get_price_thousand_separator is ignored
492
- return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
493
-
494
- }
495
-
496
- }
497
-
498
- function pys_pixel_options() {
499
- global $post;
500
-
501
- $options = array(
502
- 'woo' => array(),
503
- );
504
-
505
- if ( pys_get_option( 'woo', 'enabled' ) && pys_is_woocommerce_active() ) {
506
-
507
- $options['woo']['is_product'] = is_product();
508
- $options['woo']['add_to_cart_enabled'] = (bool) pys_get_option( 'woo', 'on_add_to_cart_btn' );
509
-
510
- if ( is_product() ) {
511
-
512
- $product = wc_get_product( $post );
513
-
514
- if ( pys_woo_product_is_type( $product, 'simple' ) ) {
515
- $options['woo']['single_product']['type'] = 'simple';
516
- $options['woo']['single_product']['add_to_cart_params'] = pys_get_woo_ajax_addtocart_params(
517
- $post->ID );
518
- } elseif ( pys_woo_product_is_type( $product, 'variable' ) ) {
519
- $options['woo']['single_product']['type'] = 'variable';
520
- $options['woo']['single_product']['add_to_cart_params'] = pys_woo_product_variations_add_to_cart_params( $product );
521
- }
522
-
523
- }
524
-
525
- }
526
-
527
- return $options;
528
-
529
- }
530
-
531
- function pys_woo_product_variations_add_to_cart_params( $product ) {
532
-
533
- $params = array();
534
- $product = wc_get_product( $product );
535
-
536
- if ( false == $product || false == pys_woo_product_is_type( $product, 'variable' ) ) {
537
- return array();
538
- }
539
-
540
- foreach ( $product->get_available_variations() as $variation ) {
541
- $params[ $variation['variation_id'] ] = pys_get_woo_ajax_addtocart_params( $variation['variation_id'] );
542
- }
543
-
544
-
545
- return $params;
546
-
547
- }
548
-
549
- function pys_woo_product_is_type( $product, $type ) {
550
-
551
- if ( pys_is_wc_version_gte( '2.7' ) ) {
552
- return $type == $product->is_type( $type );
553
- } else {
554
- return $product->product_type == $type;
555
- }
556
-
557
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ) {
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 );
16
+
17
+ } else {
18
+
19
+ return 'incl' === get_option( 'woocommerce_tax_display_shop' )
20
+ ? $product->get_price_including_tax()
21
+ : $product->get_price_excluding_tax();
22
+
23
+ }
24
+
25
+ }
26
+
27
+ if ( ! function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
28
+
29
+ function pys_get_woo_ajax_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'] = json_encode( 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 ( pys_get_option( 'woo', 'on_add_to_cart_page' ) && is_cart() ) {
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_wc_endpoint_url( 'order-received' ) ) {
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_add_code_to_woo_cart_link' ) ) {
395
+
396
+ /**
397
+ * Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
398
+ *
399
+ * @param string $tag
400
+ * @param WC_Product $product
401
+ *
402
+ * @return string
403
+ */
404
+ function pys_add_code_to_woo_cart_link( $tag, $product ) {
405
+ global $pys_woo_ajax_events;
406
+
407
+ // do not add code if AJAX is disabled. event will be processed by another function
408
+ if ( 'yes' !== get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
409
+ return $tag;
410
+ }
411
+
412
+ if ( false == pys_woo_product_is_type( $product, 'simple' ) ) {
413
+ return $tag;
414
+ }
415
+
416
+ /**
417
+ * @since 5.0.1
418
+ */
419
+ if ( pys_is_wc_version_gte( '2.6' ) ) {
420
+ $product_id = $product->get_id();
421
+ } else {
422
+ $product_id = $product->post->ID;
423
+ }
424
+
425
+ $content_id = pys_get_product_content_id( $product_id );
426
+
427
+ // common params
428
+ $params = array();
429
+ $params['content_type'] = 'product';
430
+ $params['content_ids'] = json_encode( $content_id );
431
+
432
+ // currency, value
433
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
434
+
435
+ $option = pys_get_option( 'woo', 'view_content_value_option' );
436
+ switch ( $option ) {
437
+ case 'global':
438
+ $value = pys_get_option( 'woo', 'view_content_global_value' );
439
+ break;
440
+
441
+ case 'price':
442
+ $value = pys_get_product_price( $product_id );
443
+ break;
444
+
445
+ default:
446
+ $value = null;
447
+
448
+ }
449
+
450
+ $params['value'] = $value;
451
+ $params['currency'] = get_woocommerce_currency();
452
+
453
+ }
454
+
455
+ // contents
456
+ $params['contents'] = json_encode( array(
457
+ array(
458
+ 'id' => (string) reset( $content_id ),
459
+ 'quantity' => 1,
460
+ 'item_price' => pys_get_woo_product_price_to_display( $product_id ),
461
+ )
462
+ ) );
463
+
464
+ $params = apply_filters( 'pys_event_params', $params, 'AddToCart' );
465
+
466
+ $event_id = 'pys_' . md5( serialize( $params ) );
467
+ $tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true, 'any' );
468
+
469
+ $pys_woo_ajax_events[ $event_id ] = array(
470
+ 'name' => 'AddToCart',
471
+ 'params' => $params
472
+ );
473
+
474
+ return $tag;
475
+
476
+ }
477
+
478
+ }
479
+
480
+ if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
481
+
482
+ /**
483
+ * Adds extra params to pixel init code. On Free always returns empty string.
484
+ * PRO only.
485
+ *
486
+ * @see: https://www.facebook.com/help/ipad-app/606443329504150
487
+ * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
488
+ * @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
489
+ *
490
+ * @return string
491
+ */
492
+ function pys_get_additional_matching_code() {
493
+
494
+ return ''; // PRO feature
495
+
496
+ }
497
+
498
+ }
499
+
500
+ if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
501
+
502
+ /**
503
+ * Adds additional post parameters like `content_name` and `category_name`.
504
+ * PRO only.
505
+ *
506
+ * @param $post WP_Post|int
507
+ * @param $params array reference to $params array
508
+ */
509
+ function pys_get_additional_woo_params( $post, &$params ) {
510
+
511
+ // PRO only
512
+
513
+ }
514
+
515
+ }
516
+
517
+ if ( ! function_exists( 'pys_general_woo_event' ) ) {
518
+
519
+ /**
520
+ * Add General event on Woo Product page. PRO only.
521
+ *
522
+ * @param $post WP_Post|int
523
+ * @param $track_tags bool
524
+ * @param $delay int
525
+ * @param $event_name string
526
+ */
527
+ function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
528
+ // PRO feature
529
+ }
530
+
531
+ }
532
+
533
+ if ( ! function_exists( 'pys_general_edd_event' ) ) {
534
+
535
+ /**
536
+ * Add General event on EDD Download page. PRO only.
537
+ *
538
+ * @param $post WP_Post|int
539
+ * @param $track_tags bool
540
+ * @param $delay int
541
+ * @param $event_name string
542
+ */
543
+ function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
544
+ // PRO feature
545
+ }
546
+
547
+ }
548
+
549
+ if ( ! function_exists( 'pys_get_product_price' ) ) {
550
+
551
+ /**
552
+ * Return product price depends on plugin, product and WooCommerce settings.
553
+ *
554
+ * @param $product_id
555
+ *
556
+ * @return null|int Product price
557
+ */
558
+ function pys_get_product_price( $product_id ) {
559
+
560
+ $product = wc_get_product( $product_id );
561
+
562
+ if ( false == $product instanceof WC_Product ) {
563
+ return 0;
564
+ }
565
+
566
+ if ( $product->is_taxable() ) {
567
+
568
+ if ( pys_is_wc_version_gte( '3.0' ) ) {
569
+ $value = wc_get_price_including_tax( $product, array( 'price' => $product->get_price() ) );
570
+ } else {
571
+ $value = $product->get_price_including_tax( 1, $product->get_price() );
572
+ }
573
+
574
+ } else {
575
+
576
+ if ( pys_is_wc_version_gte( '3.0' ) ) {
577
+ $value = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_price() ) );
578
+ } else {
579
+ $value = $product->get_price_excluding_tax( 1, $product->get_price() );
580
+ }
581
+
582
+ }
583
+
584
+ return $value;
585
+
586
+ }
587
+
588
+ }
589
+
590
+ if ( ! function_exists( 'pys_get_cart_total' ) ) {
591
+
592
+ function pys_get_cart_total() {
593
+ global $woocommerce;
594
+
595
+ return $woocommerce->cart->subtotal;
596
+
597
+ }
598
+
599
+ }
600
+
601
+ if ( ! function_exists( 'pys_get_order_total' ) ) {
602
+
603
+ /**
604
+ * Calculates order 'value' param depends on WooCommerce and PYS settings
605
+ */
606
+ function pys_get_order_total( $order ) {
607
+
608
+ //wc_get_price_thousand_separator is ignored
609
+ return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
610
+
611
+ }
612
+
613
+ }
614
+
615
+ function pys_pixel_options() {
616
+ global $post;
617
+
618
+ $options = array(
619
+ 'woo' => array(),
620
+ );
621
+
622
+ if ( pys_get_option( 'woo', 'enabled' ) && pys_is_woocommerce_active() ) {
623
+
624
+ $options['woo']['is_shop'] = is_shop();
625
+ $options['woo']['is_cat'] = is_product_category();
626
+ $options['woo']['is_product'] = is_product();
627
+ $options['woo']['add_to_cart_enabled'] = (bool) pys_get_option( 'woo', 'on_add_to_cart_btn' );
628
+
629
+ if ( is_product() ) {
630
+
631
+ $product = wc_get_product( $post );
632
+
633
+ if ( pys_woo_product_is_type( $product, 'simple' ) ) {
634
+ $options['woo']['single_product']['type'] = 'simple';
635
+ $options['woo']['single_product']['add_to_cart_params'] = pys_get_woo_ajax_addtocart_params(
636
+ $post->ID );
637
+ } elseif ( pys_woo_product_is_type( $product, 'variable' ) ) {
638
+ $options['woo']['single_product']['type'] = 'variable';
639
+ $options['woo']['single_product']['add_to_cart_params'] = pys_woo_product_variations_add_to_cart_params( $product );
640
+ }
641
+
642
+ }
643
+
644
+ }
645
+
646
+ $options['ajax_url'] = admin_url( 'admin-ajax.php' );
647
+
648
+ return $options;
649
+
650
+ }
651
+
652
+ function pys_woo_product_variations_add_to_cart_params( $product ) {
653
+
654
+ $params = array();
655
+ $product = wc_get_product( $product );
656
+
657
+ if ( false == $product || false == pys_woo_product_is_type( $product, 'variable' ) ) {
658
+ return array();
659
+ }
660
+
661
+ foreach ( $product->get_available_variations() as $variation ) {
662
+ $params[ $variation['variation_id'] ] = pys_get_woo_ajax_addtocart_params( $variation['variation_id'] );
663
+ }
664
+
665
+
666
+ return $params;
667
+
668
+ }
669
+
670
+ function pys_woo_product_is_type( $product, $type ) {
671
+
672
+ if ( pys_is_wc_version_gte( '2.7' ) ) {
673
+ return $type == $product->is_type( $type );
674
+ } else {
675
+ return $product->product_type == $type;
676
+ }
677
+
678
+ }
679
+
680
+ // front-end ajax handler
681
+ add_action( 'wp_ajax_pys_fb_ajax', 'pys_ajax_handler' );
682
+ add_action( 'wp_ajax_nopriv_pys_fb_ajax', 'pys_ajax_handler' );
683
+
684
+ function pys_ajax_handler() {
685
+
686
+ if ( empty( $_GET['sub_action'] ) ) {
687
+ wp_die();
688
+ }
689
+
690
+ switch ( $_GET['sub_action'] ) {
691
+ case 'get_woo_product_addtocart_params':
692
+ pys_get_woo_ajax_addtocart_params( absint( $_GET['product_id'] ) );
693
+ break;
694
+
695
+ default:
696
+ wp_die( 'Unknown sub action.' );
697
+ }
698
+
699
+ }
inc/html-tab-edd.php CHANGED
@@ -1,393 +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
- <!-- AddToCart -->
142
- <hr>
143
- <h2 class="section-title"><?php _e( 'AddToCart Event', 'pys' ); ?></h2>
144
- <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>
145
- <table class="layout">
146
-
147
- <tr>
148
- <td colspan="2" class="narrow">
149
- <?php pys_checkbox( 'edd', 'on_add_to_cart_btn', 'edd-option' ); ?>
150
- <strong><?php _e( 'Enable AddToCart on add to cart button', 'pys' ); ?></strong>
151
- </td>
152
- </tr>
153
-
154
- <tr class="tall">
155
- <td colspan="2" class="narrow">
156
- <?php pys_checkbox( 'edd', 'on_add_to_cart_checkout', 'edd-option' ); ?>
157
- <strong>Enable AddToCart on checkout page</strong>
158
- </td>
159
- </tr>
160
-
161
- <tr>
162
- <td></td>
163
- <td>
164
- <?php pys_checkbox( 'edd', 'enable_add_to_cart_value' ); ?>
165
- <?php _e( 'Enable Value', 'pys' ); ?>
166
- <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
167
- </td>
168
- </tr>
169
-
170
- <tr>
171
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
172
- <td></td>
173
- </tr>
174
-
175
- <tr class="disabled">
176
- <td class="alignright"><p class="label"><?php _e( 'Downloads price (subtotal)', 'pys' ); ?></p></td>
177
- <td>
178
- <input type="radio">
179
- </td>
180
- </tr>
181
-
182
- <tr class="disabled">
183
- <td class="alignright"><p class="label"><?php _e( 'Percent of downloads value (subtotal)', 'pys' ); ?></p></td>
184
- <td>
185
- <input type="radio">
186
- <input type="text">&nbsp;%
187
- </td>
188
- </tr>
189
-
190
- <tr>
191
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
192
- <td>
193
- <input type="radio" checked>
194
- <?php pys_text_field( 'edd', 'add_to_cart_global_value' ); ?>
195
- </td>
196
- </tr>
197
-
198
- <tr>
199
- <td></td>
200
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
201
- <strong>enable all value options</strong></td>
202
- </tr>
203
-
204
- </table>
205
-
206
- <!-- InitiateCheckout -->
207
- <hr>
208
- <h2 class="section-title"><?php _e( 'InitiateCheckout Event', 'pys' ); ?></h2>
209
- <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>
210
- <table class="layout">
211
-
212
- <tr class="tall">
213
- <td colspan="2" class="narrow">
214
- <?php pys_checkbox( 'edd', 'on_checkout_page', 'edd-option' ); ?>
215
- <strong><?php _e( 'Enable InitiateCheckout on Checkout page', 'pys' ); ?></strong>
216
- </td>
217
- </tr>
218
-
219
- <tr>
220
- <td></td>
221
- <td>
222
- <?php pys_checkbox( 'edd', 'enable_checkout_value' ); ?>
223
- <?php _e( 'Enable Value', 'pys' ); ?>
224
- <span class="help"><?php _e( 'Add value and currency - Important for ROI measurement', 'pys' ); ?></span>
225
- </td>
226
- </tr>
227
-
228
- <tr>
229
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
230
- <td></td>
231
- </tr>
232
-
233
- <tr class="disabled">
234
- <td class="alignright"><p class="label"><?php _e( 'Downloads price (subtotal)', 'pys' ); ?></p></td>
235
- <td>
236
- <input type="radio">
237
- </td>
238
- </tr>
239
-
240
- <tr class="disabled">
241
- <td class="alignright"><p
242
- class="label"><?php _e( 'Percent of downloads value (subtotal)', 'pys' ); ?></p></td>
243
- <td>
244
- <input type="radio">
245
- <input type="text">&nbsp;%
246
- </td>
247
- </tr>
248
-
249
- <tr>
250
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
251
- <td>
252
- <input type="radio" checked>
253
- <?php pys_text_field( 'edd', 'checkout_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
- <!-- Purchase -->
266
- <hr>
267
- <h2 class="section-title"><?php _e( 'Purchase Event', 'pys' ); ?></h2>
268
- <p><?php _e( 'Purchase event will be enabled on the Success Page. It is mandatory for Facebook Dynamic Product Ads.', 'pys' ); ?></p>
269
- <table class="layout">
270
-
271
- <tr class="tall">
272
- <td colspan="2" class="narrow">
273
- <?php pys_checkbox( 'edd', 'on_success_page', 'edd-option' ); ?>
274
- <strong><?php _e( 'Enable Purchase event on Success Page', 'pys' ); ?></strong>
275
- </td>
276
- </tr>
277
-
278
- <tr>
279
- <td></td>
280
- <td>
281
- <?php pys_checkbox( 'edd', 'enable_purchase_value' ); ?>
282
- <?php _e( 'Enable Value', 'pys' ); ?>
283
- <span class="help"><?php _e( 'Add value and currency - <strong>Very important for ROI
284
- measurement</strong>', 'pys' ); ?></span>
285
- </td>
286
- </tr>
287
-
288
- <tr>
289
- <td class="alignright disabled">
290
- <p class="label"><?php _e( 'Fire the event on transaction only', 'pys' ); ?></p>
291
- </td>
292
- <td>
293
- <select disabled>
294
- <option><?php _e( 'Off', 'pys' ); ?></option>
295
- </select> - <strong>This is a PRO feature</strong> - <a
296
- href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
297
- <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>
298
- </td>
299
- </tr>
300
-
301
- <tr>
302
- <td class="alignright"><p class="label big"><?php _e( 'Define value:', 'pys' ); ?></p></td>
303
- <td></td>
304
- </tr>
305
-
306
- <tr class="disabled">
307
- <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
308
- <td>
309
- <input type="radio">
310
- </td>
311
- </tr>
312
-
313
- <tr class="disabled">
314
- <td class="alignright"><p class="label"><?php _e( 'Percent of Total', 'pys' ); ?></p></td>
315
- <td>
316
- <input type="radio">
317
- <input type="text">&nbsp;%
318
- </td>
319
- </tr>
320
-
321
- <tr>
322
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
323
- <td>
324
- <input type="radio" checked>
325
- <?php pys_text_field( 'edd', 'purchase_global_value' ); ?>
326
- </td>
327
- </tr>
328
-
329
- <tr class="tall">
330
- <td></td>
331
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
332
- <strong>enable all value options</strong></td>
333
- </tr>
334
-
335
- <tr>
336
- <td class="alignright">
337
- <p class="label big"><?php _e( 'Custom Audience Optimization:', 'pys' ); ?></p>
338
- </td>
339
- <td>
340
- <span class="help"><strong>This is a PRO feature</strong> - <a
341
- href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
342
- </td>
343
- </tr>
344
-
345
- <tr class="disabled">
346
- <td></td>
347
- <td>
348
- <input type="checkbox">
349
- <strong><?php _e( 'Add Town, State and Country parameters', 'pys' ); ?></strong>
350
- <span
351
- class="help"><?php _e( 'Will pull <code>town</code>, <code>state</code> and <code>country</code>', 'pys' ); ?></span>
352
- </td>
353
- </tr>
354
-
355
- <tr class="disabled">
356
- <td></td>
357
- <td>
358
- <input type="checkbox">
359
- <strong><?php _e( 'Add Payment Method parameter', 'pys' ); ?></strong>
360
- <span class="help"><?php _e( 'Will pull <code>payment</code>', 'pys' ); ?></span>
361
- </td>
362
- </tr>
363
-
364
- <tr class="disabled">
365
- <td></td>
366
- <td>
367
- <input type="checkbox">
368
- <strong><?php _e( 'Add Coupons parameter', 'pys' ); ?></strong>
369
- <span class="help"><?php _e( 'Will pull <code>coupon_used</code> and <code>coupon_name</code>', 'pys' ); ?></span>
370
- </td>
371
- </tr>
372
-
373
- </table>
374
-
375
- <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>
376
-
377
- <!-- Activate EDD -->
378
- <hr>
379
- <table class="layout">
380
- <tr>
381
- <td class="alignright">
382
- <p class="label big"><?php _e( 'Activate Easy Digital Downloads Pixel Settings', 'pys' ); ?></p>
383
- </td>
384
- <td>
385
- <?php pys_checkbox( 'edd', 'enabled' ); ?>
386
- </td>
387
- </tr>
388
- </table>
389
-
390
- <button class="pys-btn pys-btn-blue pys-btn-big aligncenter"><?php _e( 'Save Settings', 'pys' ); ?></button>
391
-
392
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  </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,567 +1,580 @@
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">AddToCart Event</h2>
168
- <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>
169
- <table class="layout">
170
-
171
- <tr>
172
- <td colspan="2" class="narrow">
173
- <input type="checkbox" name="pys[woo][on_add_to_cart_btn]" value="1" class="woo-option"
174
- <?php pys_checkbox_state( 'woo', 'on_add_to_cart_btn' ); ?> >
175
- <strong>Enable AddToCart on add to cart button</strong>
176
- </td>
177
- </tr>
178
-
179
- <tr>
180
- <td colspan="2" class="narrow">
181
- <input type="checkbox" name="pys[woo][on_add_to_cart_page]" value="1" class="woo-option"
182
- <?php pys_checkbox_state( 'woo', 'on_add_to_cart_page' ); ?> >
183
- <strong>Enable AddToCart on cart page</strong>
184
- </td>
185
- </tr>
186
-
187
- <tr class="tall">
188
- <td colspan="2" class="narrow">
189
- <input type="checkbox" name="pys[woo][on_add_to_cart_checkout]" value="1" class="woo-option"
190
- <?php pys_checkbox_state( 'woo', 'on_add_to_cart_checkout' ); ?> >
191
- <strong>Enable AddToCart on checkout page</strong>
192
- </td>
193
- </tr>
194
-
195
- <tr>
196
- <td></td>
197
- <td>
198
- <?php pys_checkbox( 'woo', 'enable_add_to_cart_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
199
- <span class="help">Add value and currency - Important for ROI measurement</span>
200
- </td>
201
- </tr>
202
-
203
- <tr>
204
- <td class="alignright"><p class="label big">Define value:</p></td>
205
- <td></td>
206
- </tr>
207
-
208
- <tr>
209
- <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
210
- <td>
211
- <input type="radio" name="pys[woo][add_to_cart_value_option]" value="price"
212
- <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'price' ); ?> >
213
- </td>
214
- </tr>
215
-
216
- <tr class="disabled">
217
- <td class="alignright"><p class="label">Percent of product price</p></td>
218
- <td>
219
- <input type="radio">
220
- <input type="text">%
221
- </td>
222
- </tr>
223
-
224
- <tr>
225
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
226
- <td>
227
- <input type="radio" name="pys[woo][add_to_cart_value_option]" value="global"
228
- <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'global' ); ?> >
229
- <input type="text" name="pys[woo][add_to_cart_global_value]" value="<?php echo pys_get_option( 'woo', 'add_to_cart_global_value' ); ?>">
230
- </td>
231
- </tr>
232
-
233
- <tr>
234
- <td></td>
235
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
236
- <strong>enable all value options</strong></td>
237
- </tr>
238
-
239
- </table>
240
-
241
- <hr>
242
- <h2 class="section-title">InitiateCheckout Event</h2>
243
- <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>
244
- <table class="layout">
245
-
246
- <tr class="tall">
247
- <td colspan="2" class="narrow">
248
-
249
- <input type="checkbox" name="pys[woo][on_checkout_page]" value="1" class="woo-option"
250
- <?php pys_checkbox_state( 'woo', 'on_checkout_page' ); ?> >
251
- <strong>Enable InitiateCheckout on Checkout page</strong>
252
-
253
- </td>
254
- </tr>
255
-
256
- <tr>
257
- <td></td>
258
- <td>
259
- <?php pys_checkbox( 'woo', 'enable_checkout_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
260
- <span class="help">Add value and currency - Important for ROI measurement</span>
261
- </td>
262
- </tr>
263
-
264
- <tr>
265
- <td class="alignright"><p class="label big">Define value:</p></td>
266
- <td></td>
267
- </tr>
268
-
269
- <tr>
270
- <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
271
- <td>
272
- <input type="radio" name="pys[woo][checkout_value_option]" value="price"
273
- <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'price' ); ?> >
274
- </td>
275
- </tr>
276
-
277
- <tr class="disabled">
278
- <td class="alignright"><p class="label">Percent of products value (subtotal)</p></td>
279
- <td>
280
- <input type="radio">
281
- <input type="text">%
282
- </td>
283
- </tr>
284
-
285
- <tr>
286
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
287
- <td>
288
- <input type="radio" name="pys[woo][checkout_value_option]" value="global"
289
- <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'global' ); ?> >
290
- <input type="text" name="pys[woo][checkout_global_value]" value="<?php echo pys_get_option( 'woo', 'checkout_global_value' ); ?>">
291
- </td>
292
- </tr>
293
-
294
- <tr>
295
- <td></td>
296
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
297
- <strong>enable all value options</strong></td>
298
- </tr>
299
-
300
- </table>
301
-
302
- <hr>
303
- <h2 class="section-title">Purchase Event</h2>
304
- <p>Purchase event will be enabled on the Thank You page. It is mandatory for Facebook Dynamic Product Ads.</p>
305
- <table class="layout">
306
-
307
- <tr class="tall">
308
- <td colspan="2" class="narrow">
309
-
310
- <input type="checkbox" name="pys[woo][on_thank_you_page]" value="1" class="woo-option"
311
- <?php pys_checkbox_state( 'woo', 'on_thank_you_page' ); ?> >
312
- <strong>Enable Purchase event on Thank You page</strong>
313
-
314
- </td>
315
- </tr>
316
-
317
- <tr>
318
- <td></td>
319
- <td>
320
- <?php pys_checkbox( 'woo', 'enable_purchase_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
321
- <span class="help">Add value and currency - <strong>Very important for ROI measurement</strong></span>
322
- </td>
323
- </tr>
324
-
325
- <tr>
326
- <td class="alignright disabled"><p class="label"><?php _e( 'Fire the event on transaction only', 'pys' );
327
- ?></p></td>
328
- <td>
329
- <select disabled>
330
- <option><?php _e( 'Off', 'pys' ); ?></option>
331
- </select>- <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
332
- <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>
333
- </td>
334
- </tr>
335
-
336
- <tr>
337
- <td class="alignright"><p class="label big">Define value:</p></td>
338
- <td></td>
339
- </tr>
340
-
341
- <tr class="disabled">
342
- <td class="alignright"><p class="label">Transport is:</p></td>
343
- <td>
344
- <select disabled>
345
- <option selected>Included</option>
346
- </select>
347
- </td>
348
- </tr>
349
-
350
- <tr>
351
- <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
352
- <td>
353
- <input type="radio" name="pys[woo][purchase_value_option]" value="total"
354
- <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'total' ); ?> >
355
- </td>
356
- </tr>
357
-
358
- <tr class="disabled">
359
- <td class="alignright"><p class="label">Percent of Total</p></td>
360
- <td>
361
- <input type="radio">
362
- <input type="text">%
363
- </td>
364
- </tr>
365
-
366
- <tr class="tall">
367
- <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
368
- <td>
369
- <input type="radio" name="pys[woo][purchase_value_option]" value="global"
370
- <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'global' ); ?> >
371
- <input type="text" name="pys[woo][purchase_global_value]" value="<?php echo pys_get_option( 'woo', 'purchase_global_value' ); ?>">
372
- </td>
373
- </tr>
374
-
375
- <tr class="tall">
376
- <td></td>
377
- <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
378
- <strong>enable all value options</strong></td>
379
- </tr>
380
-
381
- <tr>
382
- <td class="alignright"><p class="label big">Custom Audience Optimization:</p></td>
383
- <td>
384
- <span class="help"><strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
385
- </td>
386
- </tr>
387
-
388
- <tr class="disabled">
389
- <td class="alignright"></td>
390
- <td>
391
- <input type="checkbox">
392
- <strong>Add Town, State and Country parameters</strong>
393
- <span class="help">Will pull <code>town</code>, <code>state</code> and <code>country</code></span>
394
-
395
- </td>
396
- </tr>
397
-
398
- <tr class="disabled">
399
- <td></td>
400
- <td>
401
- <input type="checkbox">
402
- <strong>Add Payment Method parameter</strong>
403
- <span class="help">Will pull <code>payment</code></span>
404
-
405
- </td>
406
- </tr>
407
-
408
- <tr class="disabled">
409
- <td></td>
410
- <td>
411
- <input type="checkbox">
412
- <strong>Add Shipping Method parameter</strong>
413
- <span class="help">Will pull <code>shipping</code></span>
414
- </td>
415
- </tr>
416
-
417
- <tr class="disabled">
418
- <td></td>
419
- <td>
420
- <input type="checkbox">
421
- <strong>Add Coupons parameter</strong>
422
- <span class="help">Will pull <code>coupon_used</code> and <code>coupon_name</code></span>
423
- </td>
424
- </tr>
425
-
426
- </table>
427
-
428
- <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>
429
-
430
- <hr>
431
- <h2 class="section-title">WooCommerce Affiliate Products Events</h2>
432
- <p>You can add an event that will trigger each time an affiliate WooCommerce product button is clicked.</p>
433
- <table class="layout">
434
-
435
- <tr class="tall">
436
- <td colspan="2" class="narrow">
437
- <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>
438
- </td>
439
- </tr>
440
-
441
- <tr class="disabled">
442
- <td class="alignright"><p class="label">Event type:</p></td>
443
- <td>
444
- <input type="radio" checked>
445
- <select disabled>
446
- <option selected>Lead</option>
447
- </select>
448
- </td>
449
- </tr>
450
-
451
- <tr class="disabled tall">
452
- <td class="alignright"><p class="label">Name of custom event:</p></td>
453
- <td>
454
- <input type="radio">
455
- <input type="text">
456
- <span class="help">* The Affiliate event will have all the parameters values specific for selected event.</span>
457
- <span class="help">* The Custom Affiliate event will have value, currency, content_name, content_type, content_ids.</span>
458
- </td>
459
- </tr>
460
-
461
- <tr class="disabled">
462
- <td class="alignright"><p class="label">Do not pull event value</p></td>
463
- <td>
464
- <input type="radio" checked>
465
- </td>
466
- </tr>
467
-
468
- <tr class="disabled">
469
- <td class="alignright"><p class="label">Event Value = Product Price</p></td>
470
- <td>
471
- <input type="radio">
472
- </td>
473
- </tr>
474
-
475
- <tr class="disabled">
476
- <td class="alignright"><p class="label">Use Global value</p></td>
477
- <td>
478
- <input type="radio">
479
- <input type="text">
480
- <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
481
- </td>
482
- </tr>
483
-
484
- </table>
485
-
486
- <hr>
487
- <h2 class="section-title">WooCommerce PayPal Standard Events</h2>
488
- <p>You can add an event that will trigger PayPal Standard button click.</p>
489
- <table class="layout">
490
-
491
- <tr class="tall">
492
- <td colspan="2" class="narrow">
493
- <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>
494
- </td>
495
- </tr>
496
-
497
- <tr class="disabled">
498
- <td class="alignright"><p class="label">Event type:</p></td>
499
- <td>
500
- <input type="radio" checked>
501
- <select disabled>
502
- <option selected>InitiatePayment</option>
503
- </select>
504
- </td>
505
- </tr>
506
-
507
- <tr class="disabled tall">
508
- <td class="alignright"><p class="label">Name of custom event:</p></td>
509
- <td>
510
- <input type="radio">
511
- <input type="text">
512
- <span class="help">* The PayPal Standard event will have all the parameters values specific for selected event.</span>
513
- <span class="help">* The Custom Affiliate event will have value, currency, content_type, content_ids.</span>
514
- </td>
515
- </tr>
516
-
517
- <tr class="disabled">
518
- <td class="alignright"><p class="label">Do not pull event value</p></td>
519
- <td>
520
- <input type="radio" checked>
521
- </td>
522
- </tr>
523
-
524
- <tr class="disabled">
525
- <td class="alignright"><p class="label">Event Value = Cart Total</p></td>
526
- <td>
527
- <input type="radio">
528
- </td>
529
- </tr>
530
-
531
- <tr class="disabled">
532
- <td class="alignright"><p class="label">Use Global value</p></td>
533
- <td>
534
- <input type="radio">
535
- <input type="text">
536
- <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
537
- </td>
538
- </tr>
539
-
540
- </table>
541
-
542
- <hr>
543
-
544
- <table class="layout">
545
-
546
- <tr class="tall">
547
- <td colspan="2" class="narrow">
548
- <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>
549
- </td>
550
- </tr>
551
-
552
- <tr>
553
- <td class="alignright">
554
- <p class="label big">Activate WooCommerce Pixel Settings</p>
555
- </td>
556
- <td>
557
- <input type="checkbox" name="pys[woo][enabled]" value="1"
558
- <?php pys_checkbox_state( 'woo', 'enabled' ); ?> >
559
- </td>
560
- </tr>
561
-
562
- </table>
563
-
564
- <button class="pys-btn pys-btn-blue pys-btn-big aligncenter">Save Settings</button>
565
-
566
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  </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
+ <input type="checkbox" name="pys[woo][on_add_to_cart_page]" value="1" class="woo-option"
195
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_page' ); ?> >
196
+ <strong>Enable AddToCart on cart page</strong>
197
+ </td>
198
+ </tr>
199
+
200
+ <tr class="tall">
201
+ <td colspan="2" class="narrow">
202
+ <input type="checkbox" name="pys[woo][on_add_to_cart_checkout]" value="1" class="woo-option"
203
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_checkout' ); ?> >
204
+ <strong>Enable AddToCart on checkout page</strong>
205
+ </td>
206
+ </tr>
207
+
208
+ <tr>
209
+ <td></td>
210
+ <td>
211
+ <?php pys_checkbox( 'woo', 'enable_add_to_cart_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
212
+ <span class="help">Add value and currency - Important for ROI measurement</span>
213
+ </td>
214
+ </tr>
215
+
216
+ <tr>
217
+ <td class="alignright"><p class="label big">Define value:</p></td>
218
+ <td></td>
219
+ </tr>
220
+
221
+ <tr>
222
+ <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
223
+ <td>
224
+ <input type="radio" name="pys[woo][add_to_cart_value_option]" value="price"
225
+ <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'price' ); ?> >
226
+ </td>
227
+ </tr>
228
+
229
+ <tr class="disabled">
230
+ <td class="alignright"><p class="label">Percent of product price</p></td>
231
+ <td>
232
+ <input type="radio">
233
+ <input type="text">%
234
+ </td>
235
+ </tr>
236
+
237
+ <tr>
238
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
239
+ <td>
240
+ <input type="radio" name="pys[woo][add_to_cart_value_option]" value="global"
241
+ <?php echo pys_radio_state( 'woo', 'add_to_cart_value_option', 'global' ); ?> >
242
+ <input type="text" name="pys[woo][add_to_cart_global_value]" value="<?php echo pys_get_option( 'woo', 'add_to_cart_global_value' ); ?>">
243
+ </td>
244
+ </tr>
245
+
246
+ <tr>
247
+ <td></td>
248
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
249
+ <strong>enable all value options</strong></td>
250
+ </tr>
251
+
252
+ </table>
253
+
254
+ <hr>
255
+ <h2 class="section-title">InitiateCheckout Event</h2>
256
+ <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>
257
+ <table class="layout">
258
+
259
+ <tr class="tall">
260
+ <td colspan="2" class="narrow">
261
+
262
+ <input type="checkbox" name="pys[woo][on_checkout_page]" value="1" class="woo-option"
263
+ <?php pys_checkbox_state( 'woo', 'on_checkout_page' ); ?> >
264
+ <strong>Enable InitiateCheckout on Checkout page</strong>
265
+
266
+ </td>
267
+ </tr>
268
+
269
+ <tr>
270
+ <td></td>
271
+ <td>
272
+ <?php pys_checkbox( 'woo', 'enable_checkout_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
273
+ <span class="help">Add value and currency - Important for ROI measurement</span>
274
+ </td>
275
+ </tr>
276
+
277
+ <tr>
278
+ <td class="alignright"><p class="label big">Define value:</p></td>
279
+ <td></td>
280
+ </tr>
281
+
282
+ <tr>
283
+ <td class="alignright"><p class="label"><?php _e( 'Products price (subtotal)', 'pys' ); ?></p></td>
284
+ <td>
285
+ <input type="radio" name="pys[woo][checkout_value_option]" value="price"
286
+ <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'price' ); ?> >
287
+ </td>
288
+ </tr>
289
+
290
+ <tr class="disabled">
291
+ <td class="alignright"><p class="label">Percent of products value (subtotal)</p></td>
292
+ <td>
293
+ <input type="radio">
294
+ <input type="text">%
295
+ </td>
296
+ </tr>
297
+
298
+ <tr>
299
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
300
+ <td>
301
+ <input type="radio" name="pys[woo][checkout_value_option]" value="global"
302
+ <?php echo pys_radio_state( 'woo', 'checkout_value_option', 'global' ); ?> >
303
+ <input type="text" name="pys[woo][checkout_global_value]" value="<?php echo pys_get_option( 'woo', 'checkout_global_value' ); ?>">
304
+ </td>
305
+ </tr>
306
+
307
+ <tr>
308
+ <td></td>
309
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
310
+ <strong>enable all value options</strong></td>
311
+ </tr>
312
+
313
+ </table>
314
+
315
+ <hr>
316
+ <h2 class="section-title">Purchase Event</h2>
317
+ <p>Purchase event will be enabled on the Thank You page. It is mandatory for Facebook Dynamic Product Ads.</p>
318
+ <table class="layout">
319
+
320
+ <tr class="tall">
321
+ <td colspan="2" class="narrow">
322
+
323
+ <input type="checkbox" name="pys[woo][on_thank_you_page]" value="1" class="woo-option"
324
+ <?php pys_checkbox_state( 'woo', 'on_thank_you_page' ); ?> >
325
+ <strong>Enable Purchase event on Thank You page</strong>
326
+
327
+ </td>
328
+ </tr>
329
+
330
+ <tr>
331
+ <td></td>
332
+ <td>
333
+ <?php pys_checkbox( 'woo', 'enable_purchase_value' ); ?><?php _e( 'Enable Value', 'pys' ); ?>
334
+ <span class="help">Add value and currency - <strong>Very important for ROI measurement</strong></span>
335
+ </td>
336
+ </tr>
337
+
338
+ <tr>
339
+ <td class="alignright disabled"><p class="label"><?php _e( 'Fire the event on transaction only', 'pys' );
340
+ ?></p></td>
341
+ <td>
342
+ <select disabled>
343
+ <option><?php _e( 'Off', 'pys' ); ?></option>
344
+ </select>- <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
345
+ <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>
346
+ </td>
347
+ </tr>
348
+
349
+ <tr>
350
+ <td class="alignright"><p class="label big">Define value:</p></td>
351
+ <td></td>
352
+ </tr>
353
+
354
+ <tr class="disabled">
355
+ <td class="alignright"><p class="label">Transport is:</p></td>
356
+ <td>
357
+ <select disabled>
358
+ <option selected>Included</option>
359
+ </select>
360
+ </td>
361
+ </tr>
362
+
363
+ <tr>
364
+ <td class="alignright"><p class="label"><?php _e( 'Total', 'pys' ); ?></p></td>
365
+ <td>
366
+ <input type="radio" name="pys[woo][purchase_value_option]" value="total"
367
+ <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'total' ); ?> >
368
+ </td>
369
+ </tr>
370
+
371
+ <tr class="disabled">
372
+ <td class="alignright"><p class="label">Percent of Total</p></td>
373
+ <td>
374
+ <input type="radio">
375
+ <input type="text">%
376
+ </td>
377
+ </tr>
378
+
379
+ <tr class="tall">
380
+ <td class="alignright"><p class="label"><?php _e( 'Use Global value', 'pys' ); ?></p></td>
381
+ <td>
382
+ <input type="radio" name="pys[woo][purchase_value_option]" value="global"
383
+ <?php echo pys_radio_state( 'woo', 'purchase_value_option', 'global' ); ?> >
384
+ <input type="text" name="pys[woo][purchase_global_value]" value="<?php echo pys_get_option( 'woo', 'purchase_global_value' ); ?>">
385
+ </td>
386
+ </tr>
387
+
388
+ <tr class="tall">
389
+ <td></td>
390
+ <td><a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update to PRO</a> to
391
+ <strong>enable all value options</strong></td>
392
+ </tr>
393
+
394
+ <tr>
395
+ <td class="alignright"><p class="label big">Custom Audience Optimization:</p></td>
396
+ <td>
397
+ <span class="help"><strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></span>
398
+ </td>
399
+ </tr>
400
+
401
+ <tr class="disabled">
402
+ <td class="alignright"></td>
403
+ <td>
404
+ <input type="checkbox">
405
+ <strong>Add Town, State and Country parameters</strong>
406
+ <span class="help">Will pull <code>town</code>, <code>state</code> and <code>country</code></span>
407
+
408
+ </td>
409
+ </tr>
410
+
411
+ <tr class="disabled">
412
+ <td></td>
413
+ <td>
414
+ <input type="checkbox">
415
+ <strong>Add Payment Method parameter</strong>
416
+ <span class="help">Will pull <code>payment</code></span>
417
+
418
+ </td>
419
+ </tr>
420
+
421
+ <tr class="disabled">
422
+ <td></td>
423
+ <td>
424
+ <input type="checkbox">
425
+ <strong>Add Shipping Method parameter</strong>
426
+ <span class="help">Will pull <code>shipping</code></span>
427
+ </td>
428
+ </tr>
429
+
430
+ <tr class="disabled">
431
+ <td></td>
432
+ <td>
433
+ <input type="checkbox">
434
+ <strong>Add Coupons parameter</strong>
435
+ <span class="help">Will pull <code>coupon_used</code> and <code>coupon_name</code></span>
436
+ </td>
437
+ </tr>
438
+
439
+ </table>
440
+
441
+ <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>
442
+
443
+ <hr>
444
+ <h2 class="section-title">WooCommerce Affiliate Products Events</h2>
445
+ <p>You can add an event that will trigger each time an affiliate WooCommerce product button is clicked.</p>
446
+ <table class="layout">
447
+
448
+ <tr class="tall">
449
+ <td colspan="2" class="narrow">
450
+ <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>
451
+ </td>
452
+ </tr>
453
+
454
+ <tr class="disabled">
455
+ <td class="alignright"><p class="label">Event type:</p></td>
456
+ <td>
457
+ <input type="radio" checked>
458
+ <select disabled>
459
+ <option selected>Lead</option>
460
+ </select>
461
+ </td>
462
+ </tr>
463
+
464
+ <tr class="disabled tall">
465
+ <td class="alignright"><p class="label">Name of custom event:</p></td>
466
+ <td>
467
+ <input type="radio">
468
+ <input type="text">
469
+ <span class="help">* The Affiliate event will have all the parameters values specific for selected event.</span>
470
+ <span class="help">* The Custom Affiliate event will have value, currency, content_name, content_type, content_ids.</span>
471
+ </td>
472
+ </tr>
473
+
474
+ <tr class="disabled">
475
+ <td class="alignright"><p class="label">Do not pull event value</p></td>
476
+ <td>
477
+ <input type="radio" checked>
478
+ </td>
479
+ </tr>
480
+
481
+ <tr class="disabled">
482
+ <td class="alignright"><p class="label">Event Value = Product Price</p></td>
483
+ <td>
484
+ <input type="radio">
485
+ </td>
486
+ </tr>
487
+
488
+ <tr class="disabled">
489
+ <td class="alignright"><p class="label">Use Global value</p></td>
490
+ <td>
491
+ <input type="radio">
492
+ <input type="text">
493
+ <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
494
+ </td>
495
+ </tr>
496
+
497
+ </table>
498
+
499
+ <hr>
500
+ <h2 class="section-title">WooCommerce PayPal Standard Events</h2>
501
+ <p>You can add an event that will trigger PayPal Standard button click.</p>
502
+ <table class="layout">
503
+
504
+ <tr class="tall">
505
+ <td colspan="2" class="narrow">
506
+ <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>
507
+ </td>
508
+ </tr>
509
+
510
+ <tr class="disabled">
511
+ <td class="alignright"><p class="label">Event type:</p></td>
512
+ <td>
513
+ <input type="radio" checked>
514
+ <select disabled>
515
+ <option selected>InitiatePayment</option>
516
+ </select>
517
+ </td>
518
+ </tr>
519
+
520
+ <tr class="disabled tall">
521
+ <td class="alignright"><p class="label">Name of custom event:</p></td>
522
+ <td>
523
+ <input type="radio">
524
+ <input type="text">
525
+ <span class="help">* The PayPal Standard event will have all the parameters values specific for selected event.</span>
526
+ <span class="help">* The Custom Affiliate event will have value, currency, content_type, content_ids.</span>
527
+ </td>
528
+ </tr>
529
+
530
+ <tr class="disabled">
531
+ <td class="alignright"><p class="label">Do not pull event value</p></td>
532
+ <td>
533
+ <input type="radio" checked>
534
+ </td>
535
+ </tr>
536
+
537
+ <tr class="disabled">
538
+ <td class="alignright"><p class="label">Event Value = Cart Total</p></td>
539
+ <td>
540
+ <input type="radio">
541
+ </td>
542
+ </tr>
543
+
544
+ <tr class="disabled">
545
+ <td class="alignright"><p class="label">Use Global value</p></td>
546
+ <td>
547
+ <input type="radio">
548
+ <input type="text">
549
+ <span class="help">* Set this if you want a unique global value every time affiliate product clicked.</span>
550
+ </td>
551
+ </tr>
552
+
553
+ </table>
554
+
555
+ <hr>
556
+
557
+ <table class="layout">
558
+
559
+ <tr class="tall">
560
+ <td colspan="2" class="narrow">
561
+ <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>
562
+ </td>
563
+ </tr>
564
+
565
+ <tr>
566
+ <td class="alignright">
567
+ <p class="label big">Activate WooCommerce Pixel Settings</p>
568
+ </td>
569
+ <td>
570
+ <input type="checkbox" name="pys[woo][enabled]" value="1"
571
+ <?php pys_checkbox_state( 'woo', 'enabled' ); ?> >
572
+ </td>
573
+ </tr>
574
+
575
+ </table>
576
+
577
+ <button class="pys-btn pys-btn-blue pys-btn-big aligncenter">Save Settings</button>
578
+
579
+ </div>
580
  </div>
inc/integrations/facebook-for-woocommerce.php CHANGED
@@ -1,225 +1,239 @@
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, $user_info ) {
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
- // Call $product->get_id() instead of ->id to account for Variable
76
- // products, which have their own variant_ids.
77
- $retailer_id = $product->get_sku() ? $product->get_sku() . '_' .
78
- $product->get_id() : 'wc_post_id_' . $product->get_id();
79
-
80
- $ids = array(
81
- $product->get_sku(),
82
- 'wc_post_id_' . $product->get_id(),
83
- $retailer_id
84
- );
85
-
86
- return $ids;
87
-
88
- }
89
-
90
- add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
91
- function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
92
-
93
- if( $content_id_format !== 'facebook_for_woocommerce' ) {
94
- return $content_type;
95
- }
96
-
97
- if ( $product_type == 'variable' ) {
98
- return 'product_group';
99
- } else {
100
- return 'product';
101
- }
102
-
103
- }
104
-
105
- add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
106
- function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
107
-
108
- if ( $content_id_format !== 'facebook_for_woocommerce' ) {
109
- return $product_id;
110
- }
111
-
112
- if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
113
- return $cart_item['variation_id'];
114
- } else {
115
- return $cart_item['product_id'];
116
- }
117
-
118
- }
119
-
120
- add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
121
- function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
122
-
123
- $setting_defaults['woo']['content_id_format'] = 'default';
124
-
125
- return $setting_defaults;
126
-
127
- }
128
-
129
- add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
130
- function pys_fb_pixel_admin_woo_content_id_before() {
131
-
132
- ?>
133
-
134
- <tr class="tall">
135
- <td colspan="2" class="narrow">
136
- <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>
137
- <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>
138
-
139
- <p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
140
-
141
- <p style="margin-top: 0;">
142
- <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>
143
- </p>
144
-
145
- <p style="margin-top: 0;">
146
- <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>
147
- </p>
148
-
149
- <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>
150
- </td>
151
- </tr>
152
-
153
-
154
- <script type="text/javascript">
155
- jQuery(document).ready(function ($) {
156
-
157
- $('input[name="pys[woo][content_id_format]"]').change(function (e) {
158
- toggleContentIDFormatControls();
159
- });
160
-
161
- toggleContentIDFormatControls();
162
-
163
- function toggleContentIDFormatControls() {
164
-
165
- var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
166
-
167
- if (format == 'default') {
168
- $('.content_id', '#woo_content_id' ).show();
169
- } else {
170
- $('.content_id', '#woo_content_id').hide();
171
- }
172
-
173
- }
174
-
175
- });
176
- </script>
177
-
178
- <?php
179
- }
180
-
181
- add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
182
- function fb_for_woo_admin_notice_display() {
183
-
184
- $user_id = get_current_user_id();
185
-
186
- if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
187
- return;
188
- }
189
-
190
- ?>
191
-
192
- <div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
193
- <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>
194
- </div>
195
-
196
- <script type="text/javascript">
197
- jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
198
-
199
- jQuery.ajax({
200
- url: ajaxurl,
201
- data: {
202
- action: 'fb_for_woo_admin_notice_dismiss',
203
- nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
204
- user_id: '<?php echo $user_id; ?>'
205
- }
206
- })
207
-
208
- })
209
- </script>
210
-
211
- <?php
212
- }
213
-
214
- add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
215
- function fb_for_woo_admin_notice_dismiss_handler() {
216
-
217
- if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
218
- return;
219
- }
220
-
221
- add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
222
-
223
- }
224
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  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, $user_info ) {
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
+ // Call $product->get_id() instead of ->id to account for Variable
76
+ // products, which have their own variant_ids.
77
+ $retailer_id = $product->get_sku()
78
+ ? $product->get_sku() . '_' . $product->get_id()
79
+ : false;
80
+
81
+ $ids = array(
82
+ $product->get_sku(),
83
+ 'wc_post_id_' . $product->get_id(),
84
+ $retailer_id
85
+ );
86
+
87
+ return array_values( array_filter( $ids ) );
88
+
89
+ }
90
+
91
+ add_filter( 'pys_event_params', 'fb_for_woo_pys_event_params', 99, 2 );
92
+ function fb_for_woo_pys_event_params( $params, $event ) {
93
+
94
+ if ( pys_get_option( 'woo', 'content_id_format' ) == 'facebook_for_woocommerce' ) {
95
+ // Unset 'contents' parameter to avoid conflict with Facebook for WooCommerce plugin as of it is not
96
+ // support new Dynamic Ads parameters
97
+ unset( $params['contents'] );
98
+ }
99
+
100
+ return $params;
101
+
102
+ }
103
+
104
+ add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
105
+ function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
106
+
107
+ if( $content_id_format !== 'facebook_for_woocommerce' ) {
108
+ return $content_type;
109
+ }
110
+
111
+ if ( $product_type == 'variable' ) {
112
+ return 'product_group';
113
+ } else {
114
+ return 'product';
115
+ }
116
+
117
+ }
118
+
119
+ add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
120
+ function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
121
+
122
+ if ( $content_id_format !== 'facebook_for_woocommerce' ) {
123
+ return $product_id;
124
+ }
125
+
126
+ if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
127
+ return $cart_item['variation_id'];
128
+ } else {
129
+ return $cart_item['product_id'];
130
+ }
131
+
132
+ }
133
+
134
+ add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
135
+ function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
136
+
137
+ $setting_defaults['woo']['content_id_format'] = 'default';
138
+
139
+ return $setting_defaults;
140
+
141
+ }
142
+
143
+ add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
144
+ function pys_fb_pixel_admin_woo_content_id_before() {
145
+
146
+ ?>
147
+
148
+ <tr class="tall">
149
+ <td colspan="2" class="narrow">
150
+ <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>
151
+ <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>
152
+
153
+ <p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
154
+
155
+ <p style="margin-top: 0;">
156
+ <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>
157
+ </p>
158
+
159
+ <p style="margin-top: 0;">
160
+ <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>
161
+ </p>
162
+
163
+ <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>
164
+ </td>
165
+ </tr>
166
+
167
+
168
+ <script type="text/javascript">
169
+ jQuery(document).ready(function ($) {
170
+
171
+ $('input[name="pys[woo][content_id_format]"]').change(function (e) {
172
+ toggleContentIDFormatControls();
173
+ });
174
+
175
+ toggleContentIDFormatControls();
176
+
177
+ function toggleContentIDFormatControls() {
178
+
179
+ var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
180
+
181
+ if (format == 'default') {
182
+ $('.content_id', '#woo_content_id' ).show();
183
+ } else {
184
+ $('.content_id', '#woo_content_id').hide();
185
+ }
186
+
187
+ }
188
+
189
+ });
190
+ </script>
191
+
192
+ <?php
193
+ }
194
+
195
+ add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
196
+ function fb_for_woo_admin_notice_display() {
197
+
198
+ $user_id = get_current_user_id();
199
+
200
+ if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
201
+ return;
202
+ }
203
+
204
+ ?>
205
+
206
+ <div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
207
+ <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>
208
+ </div>
209
+
210
+ <script type="text/javascript">
211
+ jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
212
+
213
+ jQuery.ajax({
214
+ url: ajaxurl,
215
+ data: {
216
+ action: 'fb_for_woo_admin_notice_dismiss',
217
+ nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
218
+ user_id: '<?php echo $user_id; ?>'
219
+ }
220
+ })
221
+
222
+ })
223
+ </script>
224
+
225
+ <?php
226
+ }
227
+
228
+ add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
229
+ function fb_for_woo_admin_notice_dismiss_handler() {
230
+
231
+ if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
232
+ return;
233
+ }
234
+
235
+ add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
236
+
237
+ }
238
+
239
  endif;
js/public.js CHANGED
@@ -23,7 +23,7 @@ jQuery(document).ready(function( $ ) {
23
  */
24
  if (options.hasOwnProperty('woo')) {
25
 
26
- // WooCommerce single product AddToCart handler on AJAX-ed themes
27
  if (options.woo.is_product && options.woo.add_to_cart_enabled ) {
28
 
29
  $(document).on('added_to_cart', function () {
@@ -59,6 +59,32 @@ jQuery(document).ready(function( $ ) {
59
 
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
  }();
23
  */
24
  if (options.hasOwnProperty('woo')) {
25
 
26
+ // WooCommerce Single Product AJAX AddToCart handler
27
  if (options.woo.is_product && options.woo.add_to_cart_enabled ) {
28
 
29
  $(document).on('added_to_cart', function () {
59
 
60
  }
61
 
62
+ // WooCommerce Shop and Product Category AJAX AddToCart handler
63
+ if ( ( options.woo.is_shop || options.woo.is_cat ) && options.woo.add_to_cart_enabled ) {
64
+
65
+ $(document).on('adding_to_cart', function ( e, $button, data ) {
66
+
67
+ data.action = 'pys_fb_ajax';
68
+ data.sub_action = 'get_woo_product_addtocart_params';
69
+
70
+ $.get( options.ajax_url, data, function( response ) {
71
+
72
+ if ( ! response ) {
73
+ return;
74
+ }
75
+
76
+ if ( response.error ) {
77
+ return;
78
+ }
79
+
80
+ fbq('track', 'AddToCart', response.data);
81
+
82
+ });
83
+
84
+ });
85
+
86
+ }
87
+
88
  }
89
 
90
  }();
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.0.8
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -19,7 +19,7 @@ The New Facebook Pixel can be a very powerful tool for anyone doing Facebook ads
19
 
20
  [youtube https://www.youtube.com/watch?v=V_IWVxUrzSM]
21
 
22
- **PixelYourSite will help you insert the Facebook pixel code on every page of your site with just one click** and set up Custom or Standard Events.
23
 
24
  **E-commerce Ready**
25
 
@@ -41,7 +41,7 @@ Not ready to install yet? Read on some of the key features that make PYS a power
41
 
42
  * You can **insert the pixel on every page of your website with just ONE click**. No need to edit any posts or pages
43
 
44
- * **Optimize your site for Facebook Custom Audiences.** We add a special event (GeneralEvent) on every page that will send key parameters to Facebook, like content name, content ID, category name and post type. You can use it to create super-powerful Custom Audiences to retarget with your ads, or to expand your reach with Lookalike Audiences.
45
 
46
  >**How to use the GeneralEvent**
47
  >
@@ -55,7 +55,7 @@ Not ready to install yet? Read on some of the key features that make PYS a power
55
  >* domain (it will pull the domain name - useful if you are using the pixel on more than one sites)
56
  >* tags - pro version
57
  >
58
- >**Example:** you can create a Custom Audience from people that viewed articles from one specific category in the last 30 days or people that visited articles having one or more tags, a particular page (using the name or the ID), or content that has a particular word in the name.
59
  >
60
  >**2. Custom Conversions**
61
  >
@@ -81,9 +81,9 @@ Retargeting the users that performed a search on your site is a smart strategy b
81
 
82
  Tested with the latest WooCommerce version.
83
 
84
- * You can **insert the Facebook pixel and start tracking events on any WooCommerce** website with just a few clicks (Purchase, ViewContent, AddToCart, InitiateCheckout)
85
 
86
- * Out of the box **Facebook Dynamic Ads** (promote a product catalog) pixel setup for your Woocommerce website (we also have a dedicated feed plugin for Facebook Dynamic Ads Product Catalog)
87
 
88
  * Flexible AddToCart Event: the event will fire by default on add to cart button clicks. Ajax buttons are supported. Additionally, the event can be fired on the Cart Page, or on the Checkout Page (useful for some particular web structures).
89
 
@@ -97,7 +97,7 @@ Tested with the latest WooCommerce version.
97
 
98
  * **Dynamic AddToCart** is fully supported (the AddToCart event will fire on add to cart button click)
99
 
100
- * **Track conversion value for Easy Digital Downloads**
101
 
102
  * You can turn ON/OFF each Easy Digital Downloads event.
103
 
@@ -109,22 +109,22 @@ If you are serious about your Facebook ads, you'll love our [pro version](http:/
109
 
110
  * **Traffic Source and URL tags (UTM)** are added to all the events and you can use them to create Custom Audiences based on where your visitors are coming from. It is possible to track a particular Facebook Ad too.
111
 
112
- >You can create Custom Audiences based on where the traffic is coming from, like Google, Facebook or a particular referer.
113
  >
114
  >Additionally, if you are using URL parameters they will be tracked and added as parameters for all your events. This is extremely useful because you can create Custom Audiences from people coming from a particular ad or campaign, for example.
115
 
116
  Find out more on [how the pro version can help you with Custom Conversion and Custom Audiences](http://www.pixelyoursite.com/facebook-pixel-plugin/custom-audiences-conversions)
117
 
118
- * **NEW: The ClickEvent** - It will fire EVERYTIME a click is made on your site. Use it for Custom Audiences or Custom Conversions. [Find more here](http://www.pixelyoursite.com/clicks-facebook-custom-conversions-audiences)
119
 
120
  * **NEW: Head/Footer scripts** - Add any script you want with our Head/Footer option. It also works on the WooCommerce thank you page. [Find more here](http://www.pixelyoursite.com/head-footer-scripts)
121
 
122
- * **NEW: WatchVideo Event** - This event will fire on embedded videos on your site. It can be used to optimize your ads for video views or to retarget your video watchers using Custom Audiences. [Find more here](http://www.pixelyoursite.com/facebook-pixel-plugin/watchvideo-event)
123
 
124
 
125
- **Dynamic Events**
126
 
127
- Optimize your Facebook Campaigns for actions on your website with dynamic events. You can fire them:
128
 
129
  * When a URL is clicked
130
  * When a CSS element is clicked (any form button, for example)
@@ -133,7 +133,7 @@ Optimize your Facebook Campaigns for actions on your website with dynamic events
133
 
134
  Works with **almost all forms or pop-up plugins.**
135
 
136
- Fire a Dynamic Event when the visitor performs a key action on your site and optimize your ads for that event (perfect for affiliate sites, newsletter signups and so on).
137
 
138
  Additionally, you can create Custom Audiences based on these dynamic events and retarget them.
139
 
@@ -145,7 +145,7 @@ This FB feature increases the chances to correctly identify users visiting your
145
 
146
  **Improved WooCommerce & Easy Digital Downloads Integration**
147
 
148
- * **Customize each event value:** You can include or exclude tax and shipping, you can use the product price, **a percent of the product price**, or a global value. Using the proper event value can improve your ads delivery and ROI.
149
 
150
  * Delay the WooCommerce & EDD ViewContent Event, so you don't spend your money on retargeting bouncing visitors.
151
 
@@ -153,12 +153,12 @@ This FB feature increases the chances to correctly identify users visiting your
153
 
154
  * **Improved Purchase Event** - The purchase event will have payment and shipping methods, client city, state, and country, plus use of coupons and coupons names tracked as parameters.
155
 
156
- >With the Improved Purchased Event you can create extremely useful Custom Audiences and retarget them with highly efficient ads.
157
- >Example: Clients that bought products from category X for at least $100 and that never used coupon ABC.
158
  >
159
- >Retargeting this audience with products from the same or similar category and give them the coupon ABC might be a winning strategy.
160
 
161
- * **Advance Matching** is supported for all the events - it will work best for your Purchase event because we will use the client data directly.
162
 
163
  * **WooCommerce Affiliate Products Events:** you can add a dynamic event that will trigger on affiliate button clicks.
164
 
@@ -229,8 +229,8 @@ You can find it here:
229
 
230
  **Can I use the plugin for Custom Audiences or Custom Conversions?**
231
 
232
- Absolutely yes! Actually, the plugin will super-optimize your site for Custom Audiences and Custom Conversions.
233
- You will be able to create the classical ones based on URLs, but also Custom Combinations, like people who visited posts from category XYZ, or tagged with tag ABC in the last 30 days.
234
 
235
  Use the PRO version, and you'll be able to do crazy things, like targeting people that came from Google and visited products under category "blue widget", or clients who bought products of at least $100, using the discount coupon "promo".
236
 
@@ -244,7 +244,7 @@ Yes, it does. The plugin adds all the necessary events, like ViewContent, AddToC
244
 
245
  ** Do I have to manually add the events for WooCommerce?**
246
 
247
- No, you don't, the plugin will take care of everything for you.
248
 
249
  **Does it work with Easy Digital Downloads?**
250
 
@@ -252,7 +252,7 @@ Yes, it works in the same way it does with WooCommerce.
252
 
253
  **Does it work with Dynamic Ads (promote a product catalog)**
254
 
255
- Yes, all the WooCommerce and EDD pixel events are Dynamic Ads ready.
256
 
257
  **Can I fire additional events if I need to?**
258
 
@@ -267,7 +267,7 @@ With the PRO version, you can use Dynamic Events and fire them on:
267
 
268
  **Will your plugin increase the loading time of my site?**
269
 
270
- The plugin itself is really fast. However, you have to remember that the pixel has to communicate with Facebook to send all the data, and this will add a little load on your site.
271
 
272
  Will this impact on your visitors? No, because all the requests are asynchronous, meaning that the browser will continue to load and your users will not see any delay whatsoever.
273
 
@@ -300,9 +300,17 @@ We have an article about how to create Custom Reports:
300
 
301
  == Changelog ==
302
 
 
 
 
 
 
 
 
 
303
  = PixelYourSite 5.0.8 =
304
 
305
- * AddToCart new option: fire the event on the Checkout Page. It will be helpful for some websites with customized structure.
306
 
307
  * The AddToCart event was improved to work with AJAX buttons on single product pages. This will help to catch events on a number of themes that use AJAX on the product pages.
308
 
@@ -361,7 +369,7 @@ We have an article about how to create Custom Reports:
361
 
362
  = PixelYourSite 4.0.2 =
363
 
364
- * WordDpress 4.7 compatibility checked
365
 
366
  * Manage Events buttons fixed - they were not looking right on WP 4.7
367
 
@@ -386,9 +394,9 @@ We have an article about how to create Custom Reports:
386
 
387
  * Changing GeneralEvent parameters names to avoid Pixel Helper warning (post_id and post_type are now being used)
388
 
389
- * Updating new pro features (tracking tags, advanced matching)
390
 
391
- * Minor fixes and code changes
392
 
393
  = PixelYourSite 3.0.3 =
394
 
@@ -485,7 +493,7 @@ This is a major release, with a new design and new features:
485
  = PixelYourSite 1.01 =
486
 
487
  * Dynamic AddToCart event for WooCommerce (the AddToCart event will trigger when a users click on the add to cart button)
488
- * Dynamic AddToCart works with WooCommerce shortcodes.
489
  * Fixed a false error that was reported for the Purchase WooCommerce event by Pixel Helper extension on the Thank You page.
490
 
491
  = PixelYourSite 1.0 =
@@ -497,4 +505,4 @@ This is a major release, with a new design and new features:
497
 
498
  = 5.0 =
499
 
500
- Version 5.0 comes with full Easy Digital Downloads integrations plus the ability to give each WooCommerce and EDD event a global value.
4
  Requires at least: 3.0.1
5
  Requires PHP: 5.3
6
  Tested up to: 4.9
7
+ Stable tag: 5.0.9
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
19
 
20
  [youtube https://www.youtube.com/watch?v=V_IWVxUrzSM]
21
 
22
+ **PixelYourSite will help you insert the Facebook pixel code on every page of your site with just one click** and set up Custom or Standard Events.
23
 
24
  **E-commerce Ready**
25
 
41
 
42
  * You can **insert the pixel on every page of your website with just ONE click**. No need to edit any posts or pages
43
 
44
+ * **Optimise your site for Facebook Custom Audiences.** We add a special event (GeneralEvent) on every page that will send key parameters to Facebook, like content name, content ID, category name and post type. You can use it to create super-powerful Custom Audiences to retarget with your ads, or to expand your reach with Lookalike Audiences.
45
 
46
  >**How to use the GeneralEvent**
47
  >
55
  >* domain (it will pull the domain name - useful if you are using the pixel on more than one sites)
56
  >* tags - pro version
57
  >
58
+ >**Example:** you can create a Custom Audience from people that viewed articles from one specific category in the last 30 days or people that visited articles having one or more tags, a particular page (using the name or the ID), or content that has a particular word in the name.
59
  >
60
  >**2. Custom Conversions**
61
  >
81
 
82
  Tested with the latest WooCommerce version.
83
 
84
+ * You can **insert the Facebook pixel and start tracking events on any WooCommerce** website with just a few clicks (Purchase, ViewContent, AddToCart, InitiateCheckout, ViewCategory)
85
 
86
+ * Out of the box **Facebook Dynamic Ads** (promote a product catalog) pixel setup for your WooCommerce website (we also have a dedicated feed plugin for Facebook Dynamic Ads Product Catalog)
87
 
88
  * Flexible AddToCart Event: the event will fire by default on add to cart button clicks. Ajax buttons are supported. Additionally, the event can be fired on the Cart Page, or on the Checkout Page (useful for some particular web structures).
89
 
97
 
98
  * **Dynamic AddToCart** is fully supported (the AddToCart event will fire on add to cart button click)
99
 
100
+ * **Track conversion value for Easy Digital Downloads**
101
 
102
  * You can turn ON/OFF each Easy Digital Downloads event.
103
 
109
 
110
  * **Traffic Source and URL tags (UTM)** are added to all the events and you can use them to create Custom Audiences based on where your visitors are coming from. It is possible to track a particular Facebook Ad too.
111
 
112
+ >You can create Custom Audiences based on where the traffic is coming from, like Google, Facebook or a particular referrer.
113
  >
114
  >Additionally, if you are using URL parameters they will be tracked and added as parameters for all your events. This is extremely useful because you can create Custom Audiences from people coming from a particular ad or campaign, for example.
115
 
116
  Find out more on [how the pro version can help you with Custom Conversion and Custom Audiences](http://www.pixelyoursite.com/facebook-pixel-plugin/custom-audiences-conversions)
117
 
118
+ * **NEW: The ClickEvent** - It will fire EVERY TIME a click is made on your site. Use it for Custom Audiences or Custom Conversions. [Find more here](http://www.pixelyoursite.com/clicks-facebook-custom-conversions-audiences)
119
 
120
  * **NEW: Head/Footer scripts** - Add any script you want with our Head/Footer option. It also works on the WooCommerce thank you page. [Find more here](http://www.pixelyoursite.com/head-footer-scripts)
121
 
122
+ * **NEW: WatchVideo Event** - This event will fire on embedded videos on your site. It can be used to optimise your ads for video views or to retarget your video watchers using Custom Audiences. [Find more here](http://www.pixelyoursite.com/facebook-pixel-plugin/watchvideo-event)
123
 
124
 
125
+ **Dynamic Events**
126
 
127
+ Optimise your Facebook Campaigns for actions on your website with dynamic events. You can fire them:
128
 
129
  * When a URL is clicked
130
  * When a CSS element is clicked (any form button, for example)
133
 
134
  Works with **almost all forms or pop-up plugins.**
135
 
136
+ Fire a Dynamic Event when the visitor performs a key action on your site and optimise your ads for that event (perfect for affiliate sites, newsletter signups and so on).
137
 
138
  Additionally, you can create Custom Audiences based on these dynamic events and retarget them.
139
 
145
 
146
  **Improved WooCommerce & Easy Digital Downloads Integration**
147
 
148
+ * **Customise each event value:** You can include or exclude tax and shipping, you can use the product price, **a percent of the product price**, or a global value. Using the proper event value can improve your ads delivery and ROI.
149
 
150
  * Delay the WooCommerce & EDD ViewContent Event, so you don't spend your money on retargeting bouncing visitors.
151
 
153
 
154
  * **Improved Purchase Event** - The purchase event will have payment and shipping methods, client city, state, and country, plus use of coupons and coupons names tracked as parameters.
155
 
156
+ >With the Improved Purchased Event you can create extremely useful Custom Audiences and retarget them with highly efficient ads.
157
+ >Example: Clients that bought products from category X for at least $100 and that never used coupon ABC.
158
  >
159
+ >Retargeting this audience with products from the same or similar category and give them the coupon ABC might be a winning strategy.
160
 
161
+ * **Advance Matching** is supported for all the events - it will work best for your Purchase event because we will use the client data directly.
162
 
163
  * **WooCommerce Affiliate Products Events:** you can add a dynamic event that will trigger on affiliate button clicks.
164
 
229
 
230
  **Can I use the plugin for Custom Audiences or Custom Conversions?**
231
 
232
+ Absolutely yes! Actually, the plugin will super-optimize your site for Custom Audiences and Custom Conversions.
233
+ You will be able to create the classical ones based on URLs, but also Custom Combinations, like people who visited posts from category XYZ, or tagged with tag ABC in the last 30 days.
234
 
235
  Use the PRO version, and you'll be able to do crazy things, like targeting people that came from Google and visited products under category "blue widget", or clients who bought products of at least $100, using the discount coupon "promo".
236
 
244
 
245
  ** Do I have to manually add the events for WooCommerce?**
246
 
247
+ No, you don't, the plugin will take care of everything for you.
248
 
249
  **Does it work with Easy Digital Downloads?**
250
 
252
 
253
  **Does it work with Dynamic Ads (promote a product catalog)**
254
 
255
+ Yes, all the WooCommerce and EDD pixel events are Dynamic Ads ready.
256
 
257
  **Can I fire additional events if I need to?**
258
 
267
 
268
  **Will your plugin increase the loading time of my site?**
269
 
270
+ The plugin itself is really fast. However, you have to remember that the pixel has to communicate with Facebook to send all the data, and this will add a little load on your site.
271
 
272
  Will this impact on your visitors? No, because all the requests are asynchronous, meaning that the browser will continue to load and your users will not see any delay whatsoever.
273
 
300
 
301
  == Changelog ==
302
 
303
+ = PixelYourSite 5.0.9 =
304
+
305
+ * ViewCategory - new WooCommerce event, compatible with Facebook Dynamic Product Ads (DPA)
306
+
307
+ * New WooCommerce events parameter: contents - A list of JSON object that contains the product ids associated with the event as well as additional information about the products. It can help with DPA
308
+
309
+ * Declaring compatibility with WooCommerce 3.2.6
310
+
311
  = PixelYourSite 5.0.8 =
312
 
313
+ * AddToCart new option: fire the event on the Checkout Page. It will be helpful for some websites with customised structure.
314
 
315
  * The AddToCart event was improved to work with AJAX buttons on single product pages. This will help to catch events on a number of themes that use AJAX on the product pages.
316
 
369
 
370
  = PixelYourSite 4.0.2 =
371
 
372
+ * WordPress 4.7 compatibility checked
373
 
374
  * Manage Events buttons fixed - they were not looking right on WP 4.7
375
 
394
 
395
  * Changing GeneralEvent parameters names to avoid Pixel Helper warning (post_id and post_type are now being used)
396
 
397
+ * Updating new pro features (tracking tags, advanced matching)
398
 
399
+ * Minor fixes and code changes
400
 
401
  = PixelYourSite 3.0.3 =
402
 
493
  = PixelYourSite 1.01 =
494
 
495
  * Dynamic AddToCart event for WooCommerce (the AddToCart event will trigger when a users click on the add to cart button)
496
+ * Dynamic AddToCart works with WooCommerce short-codes.
497
  * Fixed a false error that was reported for the Purchase WooCommerce event by Pixel Helper extension on the Thank You page.
498
 
499
  = PixelYourSite 1.0 =
505
 
506
  = 5.0 =
507
 
508
+ Version 5.0 comes with full Easy Digital Downloads integrations plus the ability to give each WooCommerce and EDD event a global value.