Advertisement
nshelper

WPGlobaCart - Brevo - WooCommerce Email Marketing

Oct 16th, 2024
58
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.77 KB | None | 0 0
  1. public function get_tracking_data_order($order_id)
  2.     {
  3.         $order = wc_get_order($order_id);
  4.         $data = array();
  5.         $cart_id = $this->get_wc_cart_id();
  6.         $email = !empty($this->get_email_id()) ? $this->get_email_id() : '';
  7.  
  8.         if (!$this->is_user_logged_in() || $this->is_administrator()) {
  9.             $email = ! empty( $order->get_billing_email() ) ? $order->get_billing_email() : '';
  10.         }
  11.  
  12.         if ('' != $email){
  13.             $this->set_email_id_cookie($email);
  14.         }
  15.  
  16.         $data['id'] = $order->get_order_number();
  17.         $data['affiliation'] = (!empty(get_bloginfo('name')) && is_string(get_bloginfo('name'))) ? get_bloginfo('name') : '';
  18.         $data['date'] = (!empty($order->get_date_created()->date(DATE_ATOM)) && is_string($order->get_date_created()->date(DATE_ATOM))) ? $order->get_date_created()->date(DATE_ATOM) : '';
  19.         $data['subtotal'] = (!empty($order->get_subtotal()) && is_numeric($order->get_subtotal()) && !is_nan( $order->get_subtotal())) ? (float) $order->get_subtotal() : 0;
  20.         $data['total'] = (!empty($order->get_total()) && is_numeric($order->get_total()) && !is_nan( $order->get_total())) ? (float) $order->get_total() : 0;
  21.         $data['discount'] = (!empty($order->get_total_discount()) && is_numeric($order->get_total_discount()) && !is_nan($order->get_total_discount())) ? $order->get_total_discount() : 0;
  22.         $data['shipping'] = (!empty($order->get_shipping_total()) && is_numeric($order->get_shipping_total()) && !is_nan($order->get_shipping_total())) ? (float) $order->get_shipping_total() : 0;
  23.         $data['total_before_tax'] = (float) ($data['subtotal'] - $data['discount']);
  24.         $data['tax'] = (!empty($order->get_total_tax()) && is_numeric($order->get_total_tax()) && !is_nan($order->get_total_tax())) ? round($order->get_total_tax(), 2) : 0;
  25.         $data['revenue'] = (!empty($order->get_total()) && is_numeric($order->get_total()) && !is_nan($order->get_total())) ? (float) $order->get_total() : 0;
  26.         $data['currency'] = (!empty($order->get_currency()) && is_string($order->get_currency())) ? $order->get_currency() : '';
  27.         $data['url'] = (!empty($order->get_checkout_order_received_url()) && is_string($order->get_checkout_order_received_url())) ? $order->get_checkout_order_received_url() : '';
  28.  
  29.         $data['items'] = array();
  30.         foreach ($order->get_items() as $item_key => $orderitem) {
  31.            
  32.             do_action( 'woocommerce/cart_loop/start', $orderitem );
  33.            
  34.             $product = wc_get_product($orderitem->get_product_id());
  35.  
  36.             $item = array();
  37.             $item['name'] = (!empty($orderitem->get_name()) && is_string($orderitem->get_name())) ? $orderitem->get_name() : '';
  38.             $item['sku'] = (!empty($product->get_sku()) && is_string($product->get_sku())) ? $product->get_sku() : '';
  39.  
  40.             $item['id'] = (!empty($orderitem->get_product_id()) && is_numeric($orderitem->get_product_id()) && ! is_nan($orderitem->get_product_id())) ? $orderitem->get_product_id() : '';
  41.             $cats_array = wp_get_post_terms($item['id'], 'product_cat', array('fields' => 'names'));
  42.             $item['category'] = is_array($cats_array) ? implode(',', $cats_array) : '';
  43.             $item['variant_id'] = (!empty($orderitem->get_variation_id()) && is_numeric($orderitem->get_variation_id()) && !is_nan($orderitem->get_variation_id())) ? $orderitem->get_variation_id() : '';
  44.             $variation = new \WC_Product_Variation($item['variant_id']);
  45.             $item['variant_sku'] = (!empty($variation->get_sku()) && is_string($variation->get_sku())) ? $variation->get_sku() : '';
  46.             $attributes = $variation->get_attributes();
  47.             $item['variant_name'] = is_array($attributes) ? implode(',', $attributes) : '';
  48.             $item['price'] = (!empty($orderitem->get_total()) && is_numeric($orderitem->get_total()) && ! is_nan($orderitem->get_total())) ? round($orderitem->get_total(), 2) : '';
  49.             $item['tax'] = (!empty($orderitem->get_total_tax()) && is_numeric($orderitem->get_total_tax()) && ! is_nan($orderitem->get_total_tax())) ? round($orderitem->get_total_tax(), 2) : '';
  50.             $item['quantity'] = (!empty($orderitem->get_quantity()) && is_numeric($orderitem->get_quantity()) && !is_nan($orderitem->get_quantity())) ? (int) $orderitem->get_quantity() : '';
  51.             $product = wc_get_product($orderitem['product_id']);
  52.             $image_id = $variation->get_image_id() ? $variation->get_image_id() : $product->get_image_id();
  53.             $item['image'] = wp_get_attachment_image_url($image_id, 'full');
  54.  
  55.             $item['url'] = (!empty( $product->get_permalink()) && is_string($product->get_permalink())) ? $product->get_permalink() : '';
  56.             array_push($data['items'], $item);
  57.            
  58.             do_action( 'woocommerce/cart_loop/end', $orderitem );
  59.            
  60.         }
  61.  
  62.         $shipping_address = array();
  63.         $shipping_address['firstname'] = (!empty($order->get_shipping_first_name()) && is_string($order->get_shipping_first_name())) ? $order->get_shipping_first_name() : '';
  64.         $shipping_address['lastname']  = (!empty($order->get_shipping_last_name()) && is_string($order->get_shipping_last_name())) ? $order->get_shipping_last_name() : '';
  65.         $shipping_address['company']   = (!empty($order->get_shipping_company()) && is_string($order->get_shipping_company())) ? $order->get_shipping_company() : '';
  66.         $shipping_address['phone']     = '';
  67.         $shipping_address['address1']  = (!empty($order->get_shipping_address_1()) && is_string($order->get_shipping_address_1())) ? $order->get_shipping_address_1() : '';
  68.         $shipping_address['address2']  = (!empty($order->get_shipping_address_2()) && is_string($order->get_shipping_address_2())) ? $order->get_shipping_address_2() : '';
  69.         $shipping_address['city']      = (!empty( $order->get_shipping_city()) && is_string($order->get_shipping_city())) ? $order->get_shipping_city() : '';
  70.         $shipping_address['country']   = (!empty($order->get_shipping_country()) && is_string($order->get_shipping_country())) ? $order->get_shipping_country() : '';
  71.         $shipping_address['state']     = (!empty($order->get_shipping_state()) && is_string($order->get_shipping_state())) ? $order->get_shipping_state() : '';
  72.         $shipping_address['zipcode']   = (!empty($order->get_shipping_postcode()) && is_string($order->get_shipping_postcode())) ? $order->get_shipping_postcode() : '';
  73.  
  74.         $billing_address = array();
  75.         $billing_address['firstname'] = (!empty($order->get_billing_first_name()) && is_string($order->get_billing_first_name())) ? $order->get_billing_first_name() : '';
  76.         $billing_address['lastname']  = (!empty($order->get_billing_last_name()) && is_string($order->get_billing_last_name())) ? $order->get_billing_last_name() : '';
  77.         $billing_address['company']   = (!empty($order->get_billing_company()) && is_string($order->get_billing_company())) ? $order->get_billing_company() : '';
  78.         $billing_address['phone']     = (!empty( $order->get_billing_phone()) && is_string($order->get_billing_phone())) ? $order->get_billing_phone() : '';
  79.         $billing_address['address1']  = (!empty( $order->get_billing_address_1()) && is_string($order->get_billing_address_1())) ? $order->get_billing_address_1() : '';
  80.         $billing_address['address2']  = (!empty( $order->get_billing_address_2()) && is_string($order->get_billing_address_2())) ? $order->get_billing_address_2() : '';
  81.         $billing_address['city']      = (!empty( $order->get_billing_city()) && is_string($order->get_billing_city())) ? $order->get_billing_city() : '';
  82.         $billing_address['country']   = (!empty( $order->get_billing_country()) && is_string($order->get_billing_country())) ? $order->get_billing_country() : '';
  83.         $billing_address['state']     = (!empty( $order->get_billing_state()) && is_string($order->get_billing_state())) ? $order->get_billing_state() : '';
  84.         $billing_address['zipcode']   = (!empty( $order->get_billing_postcode()) && is_string($order->get_billing_postcode())) ? $order->get_billing_postcode() : '';
  85.         $billing_address['email']     = (!empty( $order->get_billing_email()) && is_string($order->get_billing_email())) ? $order->get_billing_email() : '';
  86.         $data['shipping_address']     = $shipping_address;
  87.         $data['billing_address']      = $billing_address;
  88.  
  89.         $data['payment_method']       = (!empty( $order->get_payment_method_title()) && is_string($order->get_payment_method_title())) ? $order->get_payment_method_title() : '';
  90.         $data['customer_note']        = (!empty( $order->get_customer_note()) && is_string($order->get_customer_note())) ? $order->get_customer_note() : '';
  91.         $data['shipping_method'] = '';
  92.         foreach ($order->get_shipping_methods() as $item_id => $shipping_item) {
  93.             $data['shipping_method'] = $shipping_item->get_method_title();
  94.         }
  95.  
  96.         $data['shipping_tax'] = $order->get_shipping_tax() ?? "";
  97.         $data['discount_tax'] = $order->get_discount_tax() ?? "";
  98.         $data['discount_code'] = $order->get_coupon_codes() ?? "";
  99.         $data['fee_lines'] = [];
  100.         $fees = $order->get_fees() ?? "";
  101.  
  102.         if (!empty($fees)) {
  103.             foreach ($fees as $key => $fee) {
  104.                 $data['fee_lines'][$key]['fee_name'] = $fee->get_name() ?? "";
  105.                 $data['fee_lines'][$key]['fee_total'] = $fee->get_total() ?? "";
  106.                 $data['fee_lines'][$key]['fee_tax'] = $fee->get_total_tax() ?? "";
  107.             }
  108.         }
  109.  
  110.         $data_track = array(
  111.             'email'     => $email,
  112.             'event'     => 'order_completed',
  113.             'eventdata' => array(
  114.                 'id'   => 'cart:' . $cart_id,
  115.                 'data' => $data,
  116.             ),
  117.         );
  118.  
  119.         return $data_track;
  120.     }
Advertisement
Comments
  • nshelper
    135 days
    # text 0.10 KB | 0 0
    1. \wp-content\plugins\woocommerce-sendinblue-newsletter-subscription\src\managers\cart-events-manager.php
Add Comment
Please, Sign In to add comment
Advertisement