2014-06-13 13:20:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param bool $the_order (default: false)
|
|
|
|
* @param array $args (default: array())
|
|
|
|
* @return WC_Order
|
|
|
|
*/
|
|
|
|
public function get_order( $the_order = false, $args = array() ) {
|
|
|
|
global $post;
|
|
|
|
|
|
|
|
if ( false === $the_order ) {
|
|
|
|
$the_order = $post;
|
|
|
|
} elseif ( is_numeric( $the_order ) ) {
|
|
|
|
$the_order = get_post( $the_order );
|
|
|
|
}
|
|
|
|
|
2014-07-08 17:20:40 +00:00
|
|
|
if ( ! $the_order || ! is_object( $the_order ) ) {
|
2014-06-13 13:20:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-07 10:44:27 +00:00
|
|
|
$order_id = absint( $the_order->ID );
|
|
|
|
$post_type = $the_order->post_type;
|
|
|
|
|
2014-07-11 11:43:42 +00:00
|
|
|
if ( $order_type = wc_get_order_type( $post_type ) ) {
|
|
|
|
$classname = $order_type['class_name'];
|
2014-06-13 13:20:14 +00:00
|
|
|
} else {
|
2014-07-08 17:10:37 +00:00
|
|
|
$classname = false;
|
2014-06-13 13:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter classname so that the class can be overridden if extended.
|
2014-07-11 11:43:42 +00:00
|
|
|
$classname = apply_filters( 'woocommerce_order_class', $classname, $post_type, $order_id );
|
2014-06-13 13:20:14 +00:00
|
|
|
|
2014-07-07 10:44:27 +00:00
|
|
|
if ( ! class_exists( $classname ) ) {
|
2014-06-14 21:26:01 +00:00
|
|
|
$classname = 'WC_Order';
|
2014-07-07 10:44:27 +00:00
|
|
|
}
|
2014-06-13 13:20:14 +00:00
|
|
|
|
|
|
|
return new $classname( $the_order, $args );
|
|
|
|
}
|
2014-07-07 19:19:51 +00:00
|
|
|
}
|