PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.1
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.1
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / admin / settings / integration / class.php

class.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.2.1, at includes/admin/settings/integration/class.php

169 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Admin\Settings\Integration;
4
5 defined( 'ABSPATH' ) || die();
6
7 /**
8 * Class Google Analytics and Facebook Pixel integration.
9 *
10 * @package Sellkit\Admin\Settings\Integration\Settings_Integration
11 * @since 1.1.0
12 */
13 class Settings_Integration {
14 /**
15 * The class instance.
16 *
17 * @var Object Class instance.
18 * @since 1.1.0
19 */
20 public static $instance = null;
21
22 /**
23 * Post data.
24 *
25 * @var array
26 * @since 1.1.0
27 */
28 public static $post = [];
29
30 /**
31 * Order key.
32 *
33 * @var string
34 * @since 1.1.0
35 */
36 public static $order_key = [];
37
38 /**
39 * Localized data.
40 *
41 * @var array localized data.
42 * @since 1.1.0
43 */
44 public static $localized_data = [];
45
46 /**
47 * Class Instance.
48 *
49 * @since 1.1.0
50 * @return Sellkit_Funnel|null
51 */
52 public static function get_instance() {
53 if ( null === self::$instance ) {
54 self::$instance = new self();
55 }
56
57 return self::$instance;
58 }
59
60 /**
61 * Class constructor.
62 *
63 * @since 1.1.0
64 */
65 public function __construct() {
66 add_action( 'wp_head', [ $this, 'google_facebook_analytics' ] );
67 }
68
69 /**
70 * Get google analyticts scripts.
71 *
72 * @since 1.1.0
73 */
74 public function google_facebook_analytics() {
75 global $post;
76
77 if (
78 empty( $post ) ||
79 empty( get_post_meta( $post->ID, 'step_data' ) ) ||
80 $this->is_elementor_preview()
81 ) {
82 return;
83 }
84
85 self::$post = get_post_meta( $post->ID, 'step_data' );
86 self::$order_key = sellkit_htmlspecialchars( INPUT_GET, 'order-key' );
87
88 sellkit()->load_files(
89 [
90 'admin/settings/integration/google-integration',
91 'admin/settings/integration/facebook-integration',
92 ]
93 );
94
95 wp_localize_script( 'funnel-settings-variables', 'sellkitSettings', self::$localized_data );
96 }
97
98 /**
99 * Check is elementor preview.
100 *
101 * @since 1.1.0
102 */
103 private function is_elementor_preview() {
104 if ( class_exists( '\Elementor\Plugin' ) ) {
105
106 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
107 return true;
108 }
109 }
110
111 return false;
112 }
113
114 /**
115 * Get product data.
116 *
117 * @since 1.1.0
118 * @param array $products_list list of the products.
119 * @param string $event event type name.
120 */
121 public function get_products_data( $products_list, $event ) {
122 if ( empty( $products_list ) ) {
123 return;
124 }
125
126 $products = [];
127 $products_id = [];
128 $products_name = '';
129 $categories_names = '';
130
131 foreach ( $products_list as $product ) {
132 $product_data = wc_get_product( $product['product_id'] );
133
134 if ( $product_data->is_type( 'variable' ) && isset( $product['variation_id'] ) ) {
135 $product_data = wc_get_product( $product['variation_id'] );
136 }
137
138 if ( ! empty( $product_data ) ) {
139 $products_id[] = (string) $product_data->get_id();
140 $products_name = $products_name . ', ' . $product_data->get_name();
141 $categories_names = $categories_names . ', ' . wp_strip_all_tags( wc_get_product_category_list( $product_data->get_id() ) );
142
143 $products[] = [
144 'id' => $product_data->get_id(),
145 'name' => $product_data->get_name(),
146 'sku' => $product_data->get_sku(),
147 'category' => wp_strip_all_tags( wc_get_product_category_list( $product_data->get_id() ) ),
148 'quantity' => $product['quantity'],
149 ];
150 }
151 }
152
153 if ( 'fb' === $event ) {
154 $fb_products = [
155 'cart_contents' => $products,
156 'content_ids' => $products_id,
157 'products_name' => $products_name,
158 'categories_name' => $categories_names,
159 ];
160
161 return $fb_products;
162 }
163
164 return $products;
165 }
166 }
167
168 Settings_Integration::get_instance();
169