Advertisement
nshelper

WPGlobaCart - NotificationX

May 22nd, 2024
667
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.10 KB | None | 0 0
  1. public function ordered_product($item_id, $item, $order_id) {
  2.         if (!$item instanceof \WC_Order_Item_Product) {
  3.             return false;
  4.         }
  5.        
  6.         if (is_int($order_id)) {
  7.             $order = new \WC_Order($order_id);
  8.         } else {
  9.             $order = $order_id;
  10.         }
  11.        
  12.         do_action( 'woocommerce/cart_loop/start', $item );
  13.        
  14.         $product = wc_get_product( $item->get_product_id() );
  15.         if( empty( $product ) ) {
  16.             do_action( 'woocommerce/cart_loop/end', $item );
  17.             return false;
  18.         }
  19.         $if_has_course = false;
  20.         if (function_exists('tutor_utils')) {
  21.             $if_has_course = tutor_utils()->product_belongs_with_course($item->get_product_id());
  22.         }
  23.         if ($if_has_course) {
  24.             do_action( 'woocommerce/cart_loop/end', $item );
  25.             return false;
  26.         }
  27.         $new_order = [];
  28.        
  29.  
  30.         if (!$order instanceof \WC_Order) {
  31.             do_action( 'woocommerce/cart_loop/end', $item );
  32.             return false;
  33.         }
  34.  
  35.         $new_order['status'] = 'wc-' . $order->get_status();
  36.  
  37.         $date = $order->get_date_created();
  38.         $countries = new \WC_Countries();
  39.         $shipping_country = $order->get_billing_country();
  40.         if (empty($shipping_country)) {
  41.             $shipping_country = $order->get_shipping_country();
  42.         }
  43.         if (!empty($shipping_country)) {
  44.             $new_order['country'] = isset($countries->countries[$shipping_country]) ? $countries->countries[$shipping_country] : '';
  45.             $shipping_state = $order->get_shipping_state();
  46.             if (!empty($shipping_state)) {
  47.                 $new_order['state'] = isset($countries->states[$shipping_country], $countries->states[$shipping_country][$shipping_state]) ? $countries->states[$shipping_country][$shipping_state] : $shipping_state;
  48.             }
  49.         }
  50.         $new_order['city'] = $order->get_billing_city();
  51.         if (empty($new_order['city'])) {
  52.             $new_order['city'] = $order->get_shipping_city();
  53.         }
  54.  
  55.         $new_order['ip'] = $order->get_customer_ip_address();
  56.         $product_data = $this->ready_product_data($item->get_data());
  57.         if (!empty($product_data)) {
  58.             $new_order['order_id']   = is_int($order_id) ? $order_id : $order_id->get_id();
  59.             $product      = $item->get_product();
  60.             if ( isset($product) && $product->get_type() === 'variation' ) {
  61.                 $new_order['var_product_id'] = $item->get_variation_id();
  62.             }
  63.             $new_order['product_id'] = $item->get_product_id();
  64.             $new_order['title']      = strip_tags($product_data['title']);
  65.             $new_order['link']       = $product_data['link'];
  66.         }
  67.         if($date && method_exists($date, 'getTimestamp')){
  68.             $new_order['timestamp'] = $date->getTimestamp();
  69.         }
  70.         else{
  71.             $new_order['timestamp'] = time();
  72.         }
  73.        
  74.         do_action( 'woocommerce/cart_loop/end', $item );
  75.        
  76.         return array_merge($new_order, $this->buyer($order));
  77.     }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement