forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-wc-order-factory.php
59 lines (49 loc) · 1.28 KB
/
class-wc-order-factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Order Factory Class
*
* The WooCommerce order factory creating the right order objects.
*
* @class WC_Order_Factory
* @version 2.2.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
*/
class WC_Order_Factory {
/**
* Get order.
*
* @param bool $the_order (default: false)
* @return WC_Order|bool
*/
public function get_order( $the_order = false ) {
global $post;
if ( false === $the_order ) {
$the_order = $post;
} elseif ( is_numeric( $the_order ) ) {
$the_order = get_post( $the_order );
} elseif ( $the_order instanceof WC_Order ) {
$the_order = get_post( $the_order->id );
}
if ( ! $the_order || ! is_object( $the_order ) ) {
return false;
}
$order_id = absint( $the_order->ID );
$post_type = $the_order->post_type;
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, $the_order );
if ( ! class_exists( $classname ) ) {
return false;
}
return new $classname( $the_order );
}
}