WC_Order_Factory::get_order PHP Method

get_order() public static method

Get order.
public static get_order ( mixed $order_id = false ) : WC_Order | boolean
$order_id mixed (default: false)
return WC_Order | boolean
    public static function get_order($order_id = false)
    {
        $order_id = self::get_order_id($order_id);
        if (!$order_id) {
            return false;
        }
        $post_type = get_post_type($order_id);
        if ($order_type = wc_get_order_type($post_type)) {
            $classname = $order_type['class_name'];
        } else {
            $classname = false;
        }
        // Filter classname so that the class can be overridden if extended.
        $classname = apply_filters('woocommerce_order_class', $classname, $post_type, $order_id);
        if (!class_exists($classname)) {
            return false;
        }
        try {
            return new $classname($order_id);
        } catch (Exception $e) {
            return false;
        }
    }

Usage Example

Example #1
0
 public function parse_order_data($order_id)
 {
     $result = array('amount' => 0, 'transaction_id' => 0, 'description' => '');
     $f = new WC_Order_Factory();
     $order = $f->get_order($order_id);
     if (!$order) {
         return $result;
     }
     $result['amount'] = $order->get_total() - $order->get_total_tax() - $order->get_total_shipping();
     if ($this->tax_mode === "manual") {
         $result['amount'] *= 10000;
         $result['amount'] /= 100 + floatval($this->tax_amount);
         $result['amount'] = 0.01 * round($result['amount']);
     }
     $result['transaction_id'] = $order->get_order_number();
     $result['description'] = array();
     foreach ($order->get_items() as $item) {
         $result['description'][] = $item['item_meta']['_qty'][0] . 'x' . $item['name'];
     }
     $result['description'] = implode('|', $result['description']);
     return $result;
 }
All Usage Examples Of WC_Order_Factory::get_order