PluginProbe ʕ •ᴥ•ʔ
PixelYourSite – Your smart PIXEL (TAG) & API Manager / 9.6.1
PixelYourSite – Your smart PIXEL (TAG) & API Manager v9.6.1
11.2.0.6 trunk 1.0 1.01 1.02 1.03 1.04 1.05 1.05.1 10.0.0 10.0.1 10.0.1.1 10.0.1.2 10.0.2 10.0.3 10.0.3.1 10.0.4 10.1.0 10.1.1 10.1.1.1 10.1.1.2 10.1.2.1 10.1.3 10.2.0 10.2.0.1 10.2.0.2 10.2.1 11.0.0 11.0.0.1 11.0.0.2 11.0.0.3 11.0.0.4 11.0.1 11.0.1.1 11.0.1.2 11.0.2 11.1.0 11.1.1 11.1.2 11.1.3 11.1.4 11.1.4.1 11.1.4.2 11.1.5 11.1.5.1 11.1.5.2 11.2.0 11.2.0.1 11.2.0.2 11.2.0.3 11.2.0.4 11.2.0.5 2.0 2.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.7 2.8.10 2.8.9 3.0 3.0.1 3.0.2 3.0.3 3.1.0 4.0.0 4.0.1 4.0.2 4.0.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5.2 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.2.0 5.2.1 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 7.0.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1.0 7.1.1 7.1.10 7.1.11 7.1.12 7.1.13 7.1.14 7.1.2 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.1.8 7.1.9 7.2.0 7.2.1 7.2.1.1 7.3.0 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.0.9 8.1.0 8.1.1 8.2.0 8.2.1 8.2.10 8.2.11 8.2.12 8.2.13 8.2.14 8.2.15 8.2.16 8.2.17 8.2.18 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.2.7 8.2.8 9.0.0 9.1.0 9.1.1 9.2.0 9.2.1 9.2.2 9.3.0 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.3.6 9.3.7 9.3.8 9.3.8.1 9.3.9 9.4.0 9.4.0.1 9.4.1 9.4.2 9.4.3 9.4.5 9.4.5.1 9.4.6 9.4.7 9.4.7.1 9.5.0 9.5.0.1 9.5.1 9.5.1.1 9.5.3 9.5.4 9.5.5 9.6.0 9.6.0.1 9.6.1 9.6.1.1 9.6.2 9.7.0 9.7.0.1 9.7.1 9.7.2
pixelyoursite / includes / enrich / class_enrich_order.php
pixelyoursite / includes / enrich Last commit date
views 2 years ago class_enrich_order.php 2 years ago
class_enrich_order.php
188 lines
1 <?php
2 namespace PixelYourSite;
3
4 class EnrichOrder {
5 private static $_instance;
6
7 public static function instance() {
8
9 if ( is_null( self::$_instance ) ) {
10 self::$_instance = new self();
11 }
12 return self::$_instance;
13 }
14
15 public function init() {
16 //woo
17 if(PYS()->getOption("woo_enabled_save_data_to_orders")) {
18 add_action( 'woocommerce_new_order',array($this,'woo_save_checkout_fields'),10, 1);
19 add_action( 'add_meta_boxes', array($this,'woo_add_order_meta_boxes') );
20 if(PYS()->getOption("woo_add_enrich_to_admin_email")) {
21 add_action( 'woocommerce_email_customer_details', array($this,'woo_add_enrich_to_admin_email'),80,4 );
22 }
23 }
24
25 // edd
26 if(PYS()->getOption("edd_enabled_save_data_to_orders")) {
27 add_filter('edd_payment_meta', array($this, 'edd_save_checkout_fields'),10,2);
28 add_action('edd_view_order_details_main_after', array($this, 'add_edd_order_details'));
29 }
30 }
31
32 function add_edd_order_details($payment_id) {
33 echo '<div id="edd-payment-notes" class="postbox">
34 <h3 class="hndle"><span>PixelYourSite</span></h3>';
35 echo "<div style='margin:20px'><p>With the paid plugin, you can see more data on the Easy Digital Downloads Reports page.
36 <a target='_blank' href='https://www.pixelyoursite.com/easy-digital-downloads-first-party-reports/?utm_source=free-plugin-edd-order&utm_medium=free-plugin-edd-order&utm_campaign=free-plugin-edd-order&utm_content=free-plugin-edd-order&utm_term=free-plugin-edd-order'>Click here for details.</a>
37 </p>You can stop storing this data from the plugin's <a href='".admin_url("admin.php?page=pixelyoursite&tab=edd")."' target='_blank'>Easy Digital Downloads page</a></div>";
38 include 'views/html-edd-order-box.php';
39 echo '</div>';
40 }
41
42 function woo_add_order_meta_boxes () {
43 $screen = isWooUseHPStorage()
44 ? wc_get_page_screen_id( 'shop-order' )
45 : 'shop_order';
46 add_meta_box( 'pys_enrich_fields_woo', __('PixelYourSite','pixelyoursite'),
47 array($this,"woo_render_order_fields"), $screen);
48 }
49
50 function woo_render_order_fields($post) {
51 if ($post instanceof \WP_Post) {
52 $orderId = $post->ID;
53 } elseif (method_exists($post, 'get_id')) {
54 $orderId = $post->get_id();
55 } else {
56 // Обработка ситуации, когда $post не является ни объектом \WP_Post, ни объектом с методом get_id().
57 $orderId = null; // Или другое значение по умолчанию.
58 }
59 echo "<div style='margin:20px 10px'><p>With the paid plugin, you can see more data on the WooCommerce Reports page.
60 <a href='https://www.pixelyoursite.com/woocommerce-first-party-reports?utm_source=free-plugin&utm_medium=order-page&utm_campaign=reports-order-page&utm_content=woocommerce-reports-client-page&utm_term=order-page-reports' target='_blank'>Click here for details</a>
61 </p>You can stop storing this data from the plugin's <a href='".admin_url("admin.php?page=pixelyoursite&tab=woo")."' target='_blank'>WooCommerce page</a>.</div>";
62 include 'views/html-order-meta-box.php';
63 }
64
65 function woo_save_checkout_fields($order_id) {
66 $pysData = [];
67 $pysData = $this->getPysData();
68
69 $order = wc_get_order($order_id);
70 if ( isWooCommerceVersionGte('3.0.0') ) {
71 // WooCommerce >= 3.0
72 if($order) {
73 $order->update_meta_data("pys_enrich_data",$pysData);
74 $order->save();
75 }
76
77 } else {
78 // WooCommerce < 3.0
79 update_post_meta( $order_id, 'pys_enrich_data', $pysData );
80 }
81 }
82
83 /**
84 * @param \WC_Order$order
85 * @param $sent_to_admin
86 * @param $plain_text
87 * @param $email
88 */
89
90 function woo_add_enrich_to_admin_email($order, $sent_to_admin) {
91 if($sent_to_admin) {
92 $orderId = $order->get_id();
93 echo "<h2 style='text-align: center'>". __('PixelYourSite','pixelyoursite')."</h2>";
94 echo "Your clients don't see this information! We send it to you in this \"New Order\" email. If you want to remove this data from the \"New Order\" email, open <a href='".admin_url("admin.php?page=pixelyoursite&tab=woo")."' target='_blank'>PixelYourSite's WooCommerce page</a>, disable \"Send reports data to the New Order email\" and save.
95 <br/>With PixelYourSite Professional, you can view and download this data from the plugin's own reports page. Find out how WooCommerce Reports work and how to visualize and download your data: <a href='https://www.pixelyoursite.com/woocommerce-first-party-reports?utm_source=free-plugin&utm_medium=order-email&utm_campaign=order-email-link&utm_content=woocommerce-reports&utm_term=woocommerce-reports-email-link' target='_blank'>Click here for details</a>.<br/>";
96 include 'views/html-order-meta-box.php';
97 }
98 }
99
100
101 function edd_save_checkout_fields( $payment_meta ,$init_payment_data) {
102
103 if ( 0 !== did_action('edd_pre_process_purchase') ) {
104 $pysData = [];
105
106 $pys_landing = '';
107 $pys_source = '';
108
109 $utms = getUtms(true);
110 $utms_id = getUtmsId(true);
111
112 $pys_utm = implode("|", array_map(function ($key, $value) {
113 return "$key:$value";
114 }, array_keys($utms), $utms));
115 $pys_utm_id = implode("|", array_map(function ($key, $value) {
116 return "$key:$value";
117 }, array_keys($utms_id), $utms_id));
118 $pys_browser_time = getBrowserTime();
119 if (isset($_COOKIE['pys_landing_page']) || isset($_SESSION['LandingPage'])) {
120 $pys_landing = $_COOKIE['pys_landing_page'] ?? $_SESSION['LandingPage'];
121 }
122 if (isset($_COOKIE['pysTrafficSource']) || isset($_SESSION['TrafficSource'])) {
123 $pys_source = $_COOKIE['pysTrafficSource'] ?? $_SESSION['TrafficSource'];
124 }
125 $pysData['pys_landing'] = isset($_REQUEST['pys_landing']) ? sanitize_text_field($_REQUEST['pys_landing']) : $pys_landing;
126 $pysData['pys_source'] = isset($_REQUEST['pys_source']) ? sanitize_text_field($_REQUEST['pys_source']) : $pys_source;
127 $pysData['pys_utm'] = isset($_REQUEST['pys_utm']) ? sanitize_text_field($_REQUEST['pys_utm']) : $pys_utm;
128 $pysData['pys_browser_time'] = isset($_REQUEST['pys_browser_time']) ? sanitize_text_field($_REQUEST['pys_browser_time']) : $pys_browser_time;
129
130
131 $pysData['last_pys_landing'] = isset($_REQUEST['last_pys_landing']) ? sanitize_text_field($_REQUEST['last_pys_landing']) : $pys_landing;
132 $pysData['last_pys_source'] = isset($_REQUEST['last_pys_source']) ? sanitize_text_field($_REQUEST['last_pys_source']) : $pys_source;
133 $pysData['last_pys_utm'] = isset($_REQUEST['last_pys_utm']) ? sanitize_text_field($_REQUEST['last_pys_utm']) : $pys_utm;
134
135 $pysData['pys_utm_id'] = isset($_REQUEST['pys_utm_id']) ? sanitize_text_field($_REQUEST['pys_utm_id']) : $pys_utm_id;
136 $pysData['last_pys_utm_id'] = isset($_REQUEST['last_pys_utm_id']) ? sanitize_text_field($_REQUEST['last_pys_utm_id']) : $pys_utm_id;
137
138
139 $payment_meta['pys_enrich_data'] = $pysData;
140 }
141 return $payment_meta;
142 }
143
144 function getPysData(){
145 $pysData = array();
146 $pys_landing = '';
147 $pys_source = '';
148 $utms = getUtms(true);
149 $utms_id = getUtmsId(true);
150
151 $pys_utm = implode("|", array_map(function ($key, $value) {
152 return "$key:$value";
153 }, array_keys($utms), $utms));
154 $pys_utm_id = implode("|", array_map(function ($key, $value) {
155 return "$key:$value";
156 }, array_keys($utms_id), $utms_id));
157 $pys_browser_time = getBrowserTime();
158 if (isset($_COOKIE['pys_landing_page']) || isset($_SESSION['LandingPage'])) {
159 $pys_landing = $_COOKIE['pys_landing_page'] ?? $_SESSION['LandingPage'];
160 }
161 if (isset($_COOKIE['pysTrafficSource']) || isset($_SESSION['TrafficSource'])) {
162 $pys_source = $_COOKIE['pysTrafficSource'] ?? $_SESSION['TrafficSource'];
163 }
164 PYS()->getLog()->debug("Check", $pys_source);
165 $pysData['pys_landing'] = isset($_REQUEST['pys_landing']) ? sanitize_text_field($_REQUEST['pys_landing']) : $pys_landing;
166 $pysData['pys_source'] = isset($_REQUEST['pys_source']) ? sanitize_text_field($_REQUEST['pys_source']) : $pys_source;
167 $pysData['pys_utm'] = isset($_REQUEST['pys_utm']) ? sanitize_text_field($_REQUEST['pys_utm']) : $pys_utm;
168 $pysData['pys_browser_time'] = isset($_REQUEST['pys_browser_time']) ? sanitize_text_field($_REQUEST['pys_browser_time']) : $pys_browser_time;
169
170 $pysData['last_pys_landing'] = isset($_REQUEST['last_pys_landing']) ? sanitize_text_field($_REQUEST['last_pys_landing']) : $pys_landing;
171 $pysData['last_pys_source'] = isset($_REQUEST['last_pys_source']) ? sanitize_text_field($_REQUEST['last_pys_source']) : $pys_source;
172 $pysData['last_pys_utm'] = isset($_REQUEST['last_pys_utm']) ? sanitize_text_field($_REQUEST['last_pys_utm']) : $pys_utm;
173
174 $pysData['pys_utm_id'] = isset($_REQUEST['pys_utm_id']) ? sanitize_text_field($_REQUEST['pys_utm_id']) : $pys_utm_id;
175 $pysData['last_pys_utm_id'] = isset($_REQUEST['last_pys_utm_id']) ? sanitize_text_field($_REQUEST['last_pys_utm_id']) : $pys_utm_id;
176
177 return $pysData;
178 }
179 }
180
181 /**
182 * @return EnrichOrder
183 */
184 function EnrichOrder() {
185 return EnrichOrder::instance();
186 }
187
188 EnrichOrder();