id_order = $id_order; try { $this->order = new WC_Order($this->id_order); } catch (Exception $e) { return; } } public function getFirstMessage() { return $this->order->get_customer_note(); } public function getTotalWeight() { $items = $this->order->get_items(); $order_weight = 0; $totalWeight = 0; /* Calculamos peso */ foreach ($items as $item) { if ($item['product_id'] > 0) { $product = $item->get_product(); if (!$product->is_virtual()) { $order_weight += (float) $product->get_weight() * $item['qty']; } } } $totalWeight = $totalWeight + $order_weight; return $totalWeight; } public function getSubTotal() { return $this->order->get_subtotal(); } public function getUnits() { return $this->order->get_item_count(); } public function getTotalPaid() { return $this->order->get_total(); } public function isCashOnDeliveryMethodType() { if ($this->order->get_payment_method() == 'cod') { return true; } } public function getCurrentState() { return $this->order->get_status(); } public function orderExist() { global $wpdb; return $wpdb->get_row($wpdb->prepare( "SELECT COUNT(id) as c FROM {$wpdb->prefix}posts WHERE id = %d", (int) $this->id_order) ); } public function getIdCarrier( $id_order, $id_product ) { global $wpdb; $order = new WC_Order($id_order); $shipping_methods = array(); $shipping_methods = $order->get_shipping_methods(); // Ha sido seleccionado un transportista en el checkout if (count($shipping_methods)) { foreach ($shipping_methods as $shipping_method) { $shipping_method_data = $shipping_method->get_data(); } if (isset($shipping_method_data['instance_id'])) { $id_zone = CorreosOficialCarrier::getCarrierZone($shipping_method_data['instance_id']); $order->id_carrier = $shipping_method_data['instance_id']; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}correos_oficial_carriers_products WHERE id_product=%d and id_zone=%d", $id_product, $id_zone ) ); return $result[0]->id_carrier; } } else { // Transportista aún no seleccionado (ejemplo un pedido hecho desde Woocommerce->Pedidos) return false; } } public static function getRealDnI( $order_id ) { $NifFieldRadio = CorreosOficialConfigDao::getConfigValue('NifFieldRadio'); if ('PERSONALIZED' == $NifFieldRadio && $NifFieldRadio) { $NifFieldValue = CorreosOficialConfigDao::getConfigValue('NifFieldPersonalizedValue'); } else { $NifFieldValue = 'NIF'; } return get_post_meta($order_id, $NifFieldValue, true); } // Se borran pedidos de las tablas del plugin public static function deleteOrder( $id_order ) { global $wpdb; $wpdb->delete("{$wpdb->prefix}correos_oficial_orders", array( 'id_order' => $id_order ) ); $wpdb->delete("{$wpdb->prefix}correos_oficial_saved_orders", array( 'id_order' => $id_order ) ); $wpdb->delete("{$wpdb->prefix}correos_oficial_saved_returns", array( 'id_order' => $id_order ) ); } }