Changeset 2856851
- Timestamp:
- 01/30/2023 06:34:01 AM (3 years ago)
- File:
-
- 1 edited
-
webmaxycdp/trunk/includes/class-webmaxycdp.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
webmaxycdp/trunk/includes/class-webmaxycdp.php
r2852193 r2856851 134 134 $url = "https://performanceapi.webmaxy.co/api/woocommerce/$action?data=" . $base64_encoded; 135 135 $response = wp_remote_get($url); 136 if($event == 'SESSION' || $event == 'LOGIN' || $event == 'PLACE_ORDER' ){136 if($event == 'SESSION' || $event == 'LOGIN' || $event == 'PLACE_ORDER' || $event == 'USER_REGISTER' ){ 137 137 $response=wp_remote_retrieve_body( $response ); 138 138 $response=json_decode($response); … … 192 192 add_action( 'template_redirect', array($this, 'pageLoaded')); 193 193 add_action('wp_login', array($this, 'wmxA_login_event'), 10, 2); 194 // add_action('wp_logout', array($this, 'wmxA_logout_event'), 10, 1); 194 add_action( 'user_register', array($this, 'user_register'), 10, 2 ); 195 add_action('wp_logout', array($this, 'wmxA_logout_event'), 10, 1); 195 196 add_action( 'woocommerce_add_to_cart', array($this, 'wmxA_added_to_cart_event'),25,3); 196 197 … … 218 219 'callback' => array($this, 'getOrderDetails'), 219 220 )); 221 222 register_rest_route( 'api/v1', 'login-status',array( 223 'methods' => 'GET', 224 'callback' => array($this, 'checkUserStatus'), 225 )); 220 226 221 227 … … 223 229 }); 224 230 231 } 232 233 public function user_register($user_id,$user_data){ 234 235 $data=array( 236 "ck"=>sanitize_text_field((isset($_COOKIE['__wbmxa_ckid']) ? $_COOKIE['__wbmxa_ckid'] : "" )), 237 "us"=>sanitize_text_field((isset($_SESSION['__wbmxa_usid']) ? $_SESSION['__wbmxa_usid'] : "" )), 238 "email"=>$user_data['user_email'], 239 ); 240 241 $this->wbmxa_track_request(1,$data,"USER_REGISTER",'actions'); 242 243 } 244 245 public function checkUserStatus(){ 246 $isUserLogged=false; 247 if ( isset($_SESSION['__wbmxa_loginid']) ) { 248 $isUserLogged = true; 249 } 250 $data = [ 251 'loggedin' => $isUserLogged, 252 ]; 253 wp_send_json_success( $data ); 225 254 } 226 255 … … 272 301 } 273 302 return $categories ; 303 } 304 305 306 public function wmxA_order_status_event($order_id) 307 { 308 309 $is_admin = is_admin(); 310 311 if ( $is_admin ) { 312 $order = wc_get_order( $order_id ); 313 if (empty($order) ) { return; } 314 $items = $order->get_items(); 315 $dataset=[]; 316 foreach ( $items as $key => $item ){ 317 $product = $item->get_product(); 318 if ( $product ) { 319 $obj=array( 320 'AddedItemImageURL' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 321 'AddedItemPrice' => (float) $product->get_price(), 322 'AddedItemQuantity' => $item->get_quantity(), 323 'subtotal' => $item->get_subtotal(), 324 'total' => $item->get_total(), 325 'id' => (int)$product->get_id(), 326 'title' => (string) $product->get_name(), 327 'AddedItemSKU' => (string) $product->get_sku(), 328 'AddedItemURL' => (string) $product->get_permalink() 329 ); 330 $dataset[] =$obj ; 331 } 332 } 333 $data['ck']=sanitize_text_field($_COOKIE['__wbmxa_ckid']); 334 $data['us']=sanitize_text_field($_SESSION['__wbmxa_usid']); 335 $data['order_id']=$order_id; 336 $data['items']=$dataset; 337 $data['status']=$order->get_status(); 338 $data['currency']=$order->get_currency(); 339 $data['total']=$order->get_total(); 340 $this->wbmxa_track_request(1,$data,'ORDER_STATUS_CHANGED','actions'); 341 } 274 342 } 275 343 … … 320 388 } 321 389 } 390 $DBRecord[$i]['coupons']= $order->get_coupon_codes(); 322 391 $DBRecord[$i]['order']= $order->get_data(); 323 392 $DBRecord[$i]['items']= $items; … … 377 446 return; 378 447 } 379 380 // $now = time(); 381 // if (isset($_SESSION['discard_after']) && $now > $_SESSION['discard_after']) { 382 // unset($_SESSION['__wbmxa_usid']); 383 // unset($_SESSION['__wbmxa_price']); 384 // } 385 // $_SESSION['discard_after'] = $now + 900; 386 // echo esc_html("<script> 387 // (function() { 388 // var e = 3e5, 389 // n = Math.ceil(new Date() / e) * e, 390 // o = document.createElement('script'); 391 // o.type = 'text/javascript', o.async = !0, o.id = 'wmxattrID', o.crossorigin = 'anonymous', 392 // o.src = 'https://cdn.webmaxy.co/js/wmx-attribution.js'; 393 // o.addEventListener('load', function(e) { 394 // wmxattr.init('". esc_attr($code) ."'); 395 // }); 396 // var i = document.getElementsByTagName('script')[0]; 397 // i.parentNode.insertBefore(o, i); 398 // })(); 399 // </script>"); 400 } 448 $now = time(); 449 if (isset($_SESSION['discard_after']) && $now > $_SESSION['discard_after']) { 450 unset($_SESSION['__wbmxa_usid']); 451 unset($_SESSION['__wbmxa_price']); 452 } 453 $_SESSION['discard_after'] = $now + 900; 454 455 } 456 457 function wpb_hook_javascript_footer() { 458 if(isset($_SESSION['__wbmxa_usid'])){ 459 $client_id= get_option( 'webmaxy_client_id' ); 460 $secret_id= get_option( 'webmaxy_secret_id' ); 461 if(empty($client_id) && empty($secret_id)){ 462 return; 463 } 464 $code=base64_encode($client_id.":".$secret_id); 465 $is_admin = is_admin(); 466 467 if ( $is_admin ) { 468 return; 469 } 470 $us=$_SESSION['__wbmxa_usid']; 471 ?> 472 <script> 473 var ifrm = document.createElement("iframe"); 474 ifrm.id="webmaxyloyaltyId" 475 ifrm.setAttribute("src", "https://loyalty.webmaxy.ai/loyalty/rewards?code=<?php echo $code;?>&us=<?php echo $us;?>"); 476 ifrm.style = "z-index:9999999;position: fixed;border: none;border-radius: 20px;bottom: 20px;right: 11px;min-width: 340px; min-height: 600px;display:none;"; 477 document.body.appendChild(ifrm); 478 document.getElementById('webmaxyloyaltyId').onload=function(){ 479 window.addEventListener("message", (event) => { 480 if (event.origin !== "https://loyalty.webmaxy.ai") 481 return; 482 if(event.data==="DO_SIGN_UP_OR_LOGIN"){ 483 window.location.assign("my-account") 484 } 485 if(event.data==="DO_REFRESH_WEBMAXY"){ 486 var iframe = document.getElementById('webmaxyloyaltyId'); 487 iframe.src = iframe.src; 488 } 489 }, false); 490 }; 491 492 493 494 </script> 495 <?php 496 } 497 498 } 401 499 // referral device landing_page 402 500 public function pageLoaded() { … … 526 624 public static function wmxA_logout_event( $user_logout_id ) { 527 625 // your code 626 unset($_SESSION['__wbmxa_loginid']); 528 627 } 529 628 … … 581 680 $order_data = $order->get_data(); 582 681 $data['user']=$order_data['billing']; 682 $data['coupons']=$order->get_coupon_codes(); 583 683 $this->wbmxa_track_request(1,$data,'PLACE_ORDER','actions'); 584 684 … … 588 688 589 689 590 public function wmxA_order_status_event($order_id)591 {592 593 if(isset($_COOKIE['__wbmxa_ckid']) && isset($_SESSION['__wbmxa_usid']))594 {595 $order = wc_get_order( $order_id );596 if (empty($order) ) { return; }597 598 // $order = new WC_Order( $order_id );599 $items = $order->get_items();600 $dataset=[];601 foreach ( $items as $key => $item ){602 $product = $item->get_product();603 if ( $product ) {604 $obj=array(605 'AddedItemImageURL' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->get_id())),606 'AddedItemPrice' => (float) $product->get_price(),607 'AddedItemQuantity' => $item->get_quantity(),608 'subtotal' => $item->get_subtotal(),609 'total' => $item->get_total(),610 'id' => (int)$product->get_id(),611 'title' => (string) $product->get_name(),612 'AddedItemSKU' => (string) $product->get_sku(),613 'AddedItemURL' => (string) $product->get_permalink()614 );615 $dataset[] =$obj ;616 }617 }618 $data['ck']=sanitize_text_field($_COOKIE['__wbmxa_ckid']);619 $data['us']=sanitize_text_field($_SESSION['__wbmxa_usid']);620 $data['order_id']=$order_id;621 $data['items']=$dataset;622 $data['status']=$order->get_status();623 $data['currency']=$order->get_currency();624 $data['total']=$order->get_total();625 $this->wbmxa_track_request(1,$data,'STATUS_CHANGED','actions');626 }627 }628 690 public function wmxA_cancel_order_event($order_id) 629 691 {
Note: See TracChangeset
for help on using the changeset viewer.