Merge pull request #5678 from coenjacobs/order-factory-refactor
Order factory refactor implementation (take two)
This commit is contained in:
commit
abe0d0004a
File diff suppressed because it is too large
Load Diff
|
@ -100,7 +100,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
|
||||
// Gets order total from "pay for order" page.
|
||||
if ( 0 < $order_id ) {
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$total = (float) $order->get_total();
|
||||
|
||||
// Gets order total from cart/checkout.
|
||||
|
|
|
@ -439,7 +439,7 @@ class WC_Admin_Post_Types {
|
|||
global $post, $woocommerce, $the_order;
|
||||
|
||||
if ( empty( $the_order ) || $the_order->id != $post->ID ) {
|
||||
$the_order = new WC_Order( $post->ID );
|
||||
$the_order = get_order( $post->ID );
|
||||
}
|
||||
|
||||
switch ( $column ) {
|
||||
|
@ -1180,7 +1180,7 @@ class WC_Admin_Post_Types {
|
|||
$post_ids = array_map( 'absint', (array) $_REQUEST['post'] );
|
||||
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$order = new WC_Order( $post_id );
|
||||
$order = get_order( $post_id );
|
||||
$order->update_status( $new_status, __( 'Order status changed by bulk edit:', 'woocommerce' ) );
|
||||
$changed++;
|
||||
}
|
||||
|
@ -2015,7 +2015,7 @@ class WC_Admin_Post_Types {
|
|||
$existing_permissions = $wpdb->get_results( $wpdb->prepare( "SELECT * from {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE product_id = %d GROUP BY order_id", $product_id ) );
|
||||
|
||||
foreach ( $existing_permissions as $existing_permission ) {
|
||||
$order = new WC_Order( $existing_permission->order_id );
|
||||
$order = get_order( $existing_permission->order_id );
|
||||
|
||||
if ( $order->id ) {
|
||||
// Remove permissions
|
||||
|
|
|
@ -21,7 +21,7 @@ class WC_Meta_Box_Order_Actions {
|
|||
global $theorder;
|
||||
|
||||
if ( ! is_object( $theorder ) )
|
||||
$theorder = new WC_Order( $post->ID );
|
||||
$theorder = get_order( $post->ID );
|
||||
|
||||
$order = $theorder;
|
||||
?>
|
||||
|
@ -82,7 +82,7 @@ class WC_Meta_Box_Order_Actions {
|
|||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
// Order data saved, now get it so we can manipulate status
|
||||
$order = new WC_Order( $post_id );
|
||||
$order = get_order( $post_id );
|
||||
|
||||
// Handle button actions
|
||||
if ( ! empty( $_POST['wc_order_action'] ) ) {
|
||||
|
|
|
@ -133,7 +133,7 @@ class WC_Meta_Box_Order_Data {
|
|||
global $theorder;
|
||||
|
||||
if ( ! is_object( $theorder ) ) {
|
||||
$theorder = new WC_Order( $post->ID );
|
||||
$theorder = get_order( $post->ID );
|
||||
}
|
||||
|
||||
$order = $theorder;
|
||||
|
@ -441,7 +441,7 @@ class WC_Meta_Box_Order_Data {
|
|||
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_date = %s, post_date_gmt = %s WHERE ID = %s", $date, get_gmt_from_date( $date ), $post_id ) );
|
||||
|
||||
// Order data saved, now get it so we can manipulate status
|
||||
$order = new WC_Order( $post_id );
|
||||
$order = get_order( $post_id );
|
||||
|
||||
// Order status
|
||||
$order->update_status( $_POST['order_status'] );
|
||||
|
|
|
@ -21,7 +21,7 @@ class WC_Meta_Box_Order_Items {
|
|||
global $thepostid, $theorder;
|
||||
|
||||
if ( ! is_object( $theorder ) )
|
||||
$theorder = new WC_Order( $thepostid );
|
||||
$theorder = get_order( $thepostid );
|
||||
|
||||
$order = $theorder;
|
||||
?>
|
||||
|
|
|
@ -21,7 +21,7 @@ class WC_Meta_Box_Order_Totals {
|
|||
global $theorder, $wpdb, $post;
|
||||
|
||||
if ( ! is_object( $theorder ) )
|
||||
$theorder = new WC_Order( $post->ID );
|
||||
$theorder = get_order( $post->ID );
|
||||
|
||||
$order = $theorder;
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ class WC_Report_Customer_List extends WP_List_Table {
|
|||
) );
|
||||
|
||||
if ( $order_ids ) {
|
||||
$order = new WC_Order( $order_ids[0] );
|
||||
$order = get_order( $order_ids[0] );
|
||||
|
||||
echo '<a href="' . admin_url( 'post.php?post=' . $order->id . '&action=edit' ) . '">' . $order->get_order_number() . '</a> – ' . date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) );
|
||||
} else echo '-';
|
||||
|
|
|
@ -106,7 +106,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
if ( is_wp_error( $id ) )
|
||||
return $id;
|
||||
|
||||
$order = new WC_Order( $id );
|
||||
$order = get_order( $id );
|
||||
|
||||
$order_post = get_post( $id );
|
||||
|
||||
|
@ -275,7 +275,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
if ( is_wp_error( $id ) )
|
||||
return $id;
|
||||
|
||||
$order = new WC_Order( $id );
|
||||
$order = get_order( $id );
|
||||
|
||||
if ( ! empty( $data['status'] ) ) {
|
||||
|
||||
|
|
|
@ -351,7 +351,7 @@ class WC_AJAX {
|
|||
die();
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$order->update_status( 'completed' );
|
||||
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
|
@ -376,7 +376,7 @@ class WC_AJAX {
|
|||
die();
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$order->update_status( 'processing' );
|
||||
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
|
@ -847,7 +847,7 @@ class WC_AJAX {
|
|||
$product_ids = $_POST['product_ids'];
|
||||
$loop = intval( $_POST['loop'] );
|
||||
$file_counter = 0;
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( ! is_array( $product_ids ) ) {
|
||||
$product_ids = array( $product_ids );
|
||||
|
@ -936,7 +936,7 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
$_product = get_product( $post->ID );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$class = 'new_row';
|
||||
|
||||
// Set values
|
||||
|
@ -996,7 +996,7 @@ class WC_AJAX {
|
|||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
// Add line item
|
||||
$item_id = wc_add_order_item( $order_id, array(
|
||||
|
@ -1043,7 +1043,7 @@ class WC_AJAX {
|
|||
$order_id = absint( $_POST['order_id'] );
|
||||
$order_item_ids = isset( $_POST['order_item_ids'] ) ? $_POST['order_item_ids'] : array();
|
||||
$order_item_qty = isset( $_POST['order_item_qty'] ) ? $_POST['order_item_qty'] : array();
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$order_items = $order->get_items();
|
||||
$return = array();
|
||||
|
||||
|
@ -1089,7 +1089,7 @@ class WC_AJAX {
|
|||
$order_id = absint( $_POST['order_id'] );
|
||||
$order_item_ids = isset( $_POST['order_item_ids'] ) ? $_POST['order_item_ids'] : array();
|
||||
$order_item_qty = isset( $_POST['order_item_qty'] ) ? $_POST['order_item_qty'] : array();
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$order_items = $order->get_items();
|
||||
$return = array();
|
||||
|
||||
|
@ -1169,7 +1169,7 @@ class WC_AJAX {
|
|||
|
||||
$taxes = $tax_rows = $item_taxes = $shipping_taxes = array();
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$country = strtoupper( esc_attr( $_POST['country'] ) );
|
||||
$state = strtoupper( esc_attr( $_POST['state'] ) );
|
||||
$postcode = strtoupper( esc_attr( $_POST['postcode'] ) );
|
||||
|
@ -1285,7 +1285,7 @@ class WC_AJAX {
|
|||
$is_customer_note = $note_type == 'customer' ? 1 : 0;
|
||||
|
||||
if ( $post_id > 0 ) {
|
||||
$order = new WC_Order( $post_id );
|
||||
$order = get_order( $post_id );
|
||||
$comment_id = $order->add_order_note( $note, $is_customer_note );
|
||||
|
||||
echo '<li rel="' . esc_attr( $comment_id ) . '" class="note ';
|
||||
|
|
|
@ -629,7 +629,7 @@ class WC_Checkout {
|
|||
} else {
|
||||
|
||||
if ( empty( $order ) )
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
// No payment was required for order
|
||||
$order->payment_complete();
|
||||
|
|
|
@ -89,7 +89,7 @@ class WC_Download_Handler {
|
|||
}
|
||||
|
||||
if ( $order_id ) {
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( ! $order->is_download_permitted() || $order->post_status != 'publish' ) {
|
||||
wp_die( __( 'Invalid order.', 'woocommerce' ) . ' <a href="' . esc_url( home_url() ) . '" class="wc-forward">' . __( 'Go to homepage', 'woocommerce' ) . '</a>', '', array( 'response' => 404 ) );
|
||||
|
|
|
@ -412,7 +412,7 @@ class WC_Emails {
|
|||
else
|
||||
$title = sprintf(__( 'Product #%s - %s', 'woocommerce' ), $product->id, get_the_title($product->id)) . $sku;
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$message = sprintf(__( '%s units of %s have been backordered in order %s.', 'woocommerce' ), $quantity, $title, $order->get_order_number() );
|
||||
|
||||
// CC, BCC, additional headers
|
||||
|
|
|
@ -264,7 +264,7 @@ class WC_Form_Handler {
|
|||
// Pay for existing order
|
||||
$order_key = $_GET['key'];
|
||||
$order_id = absint( $wp->query_vars['order-pay'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
$valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order );
|
||||
|
||||
|
@ -462,7 +462,7 @@ class WC_Form_Handler {
|
|||
WC()->cart->empty_cart();
|
||||
|
||||
// Load the previous order - Stop if the order does not exist
|
||||
$order = new WC_Order( absint( $_GET['order_again'] ) );
|
||||
$order = get_order( absint( $_GET['order_again'] ) );
|
||||
|
||||
if ( empty( $order->id ) ) {
|
||||
return;
|
||||
|
@ -519,7 +519,7 @@ class WC_Form_Handler {
|
|||
|
||||
$order_key = $_GET['order'];
|
||||
$order_id = absint( $_GET['order_id'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$user_can_cancel = current_user_can( 'cancel_order', $order_id );
|
||||
$order_can_cancel = $order->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ) ) );
|
||||
$redirect = $_GET['redirect'];
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?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 );
|
||||
}
|
||||
|
||||
if ( ! $the_order )
|
||||
return false;
|
||||
|
||||
if ( is_object ( $the_order ) ) {
|
||||
$order_id = absint( $the_order->ID );
|
||||
$post_type = $the_order->post_type;
|
||||
}
|
||||
|
||||
if ( 'shop_order' == $post_type ) {
|
||||
$classname = 'WC_Order';
|
||||
$order_type = 'simple';
|
||||
} else {
|
||||
$classname = false;
|
||||
$order_type = false;
|
||||
}
|
||||
|
||||
// Filter classname so that the class can be overridden if extended.
|
||||
$classname = apply_filters( 'woocommerce_order_class', $classname, $order_type, $post_type, $order_id );
|
||||
|
||||
if ( ! class_exists( $classname ) )
|
||||
$classname = 'WC_Order';
|
||||
|
||||
return new $classname( $the_order, $args );
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -52,7 +52,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
|
|||
function trigger( $order_id ) {
|
||||
|
||||
if ( $order_id ) {
|
||||
$this->object = new WC_Order( $order_id );
|
||||
$this->object = get_order( $order_id );
|
||||
$this->recipient = $this->object->billing_email;
|
||||
|
||||
$this->find['order-date'] = '{order_date}';
|
||||
|
|
|
@ -54,7 +54,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
|
|||
function trigger( $order ) {
|
||||
|
||||
if ( ! is_object( $order ) ) {
|
||||
$order = new WC_Order( absint( $order ) );
|
||||
$order = get_order( absint( $order ) );
|
||||
}
|
||||
|
||||
if ( $order ) {
|
||||
|
|
|
@ -63,7 +63,7 @@ class WC_Email_Customer_Note extends WC_Email {
|
|||
|
||||
extract( $args );
|
||||
|
||||
$this->object = new WC_Order( $order_id );
|
||||
$this->object = get_order( $order_id );
|
||||
$this->recipient = $this->object->billing_email;
|
||||
$this->customer_note = $customer_note;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
|
|||
function trigger( $order_id ) {
|
||||
|
||||
if ( $order_id ) {
|
||||
$this->object = new WC_Order( $order_id );
|
||||
$this->object = get_order( $order_id );
|
||||
$this->recipient = $this->object->billing_email;
|
||||
|
||||
$this->find['order-date'] = '{order_date}';
|
||||
|
|
|
@ -59,7 +59,7 @@ class WC_Email_New_Order extends WC_Email {
|
|||
function trigger( $order_id ) {
|
||||
|
||||
if ( $order_id ) {
|
||||
$this->object = new WC_Order( $order_id );
|
||||
$this->object = get_order( $order_id );
|
||||
|
||||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
|
|
@ -291,7 +291,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
|
|||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
// Mark as on-hold (we're awaiting the payment)
|
||||
$order->update_status( 'on-hold', __( 'Awaiting BACS payment', 'woocommerce' ) );
|
||||
|
|
|
@ -108,7 +108,7 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
|
|||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
// Mark as on-hold (we're awaiting the cheque)
|
||||
$order->update_status( 'on-hold', __( 'Awaiting cheque payment', 'woocommerce' ) );
|
||||
|
|
|
@ -120,7 +120,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
|||
|
||||
if ( is_page( wc_get_page_id( 'checkout' ) ) && 0 < get_query_var( 'order-pay' ) ) {
|
||||
$order_id = absint( get_query_var( 'order-pay' ) );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
// Test if order needs shipping.
|
||||
$needs_shipping = false;
|
||||
|
@ -198,7 +198,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
|||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
// Mark as processing (payment won't be taken until delivery)
|
||||
$order->update_status( 'processing', __( 'Payment to be made upon delivery.', 'woocommerce' ) );
|
||||
|
|
|
@ -88,7 +88,7 @@ class WC_Gateway_Mijireh extends WC_Payment_Gateway {
|
|||
try {
|
||||
$mj_order = new Mijireh_Order( esc_attr( $_GET['order_number'] ) );
|
||||
$wc_order_id = $mj_order->get_meta_value( 'wc_order_id' );
|
||||
$wc_order = new WC_Order( absint( $wc_order_id ) );
|
||||
$wc_order = get_order( absint( $wc_order_id ) );
|
||||
|
||||
// Mark order complete
|
||||
$wc_order->payment_complete();
|
||||
|
@ -188,7 +188,7 @@ class WC_Gateway_Mijireh extends WC_Payment_Gateway {
|
|||
$this->init_mijireh();
|
||||
|
||||
$mj_order = new Mijireh_Order();
|
||||
$wc_order = new WC_Order( $order_id );
|
||||
$wc_order = get_order( $order_id );
|
||||
|
||||
// Avoid rounding issues altogether by sending the order as one lump
|
||||
if ( get_option( 'woocommerce_prices_include_tax' ) == 'yes' ) {
|
||||
|
|
|
@ -445,7 +445,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
*/
|
||||
function generate_paypal_form( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( 'yes' == $this->testmode ) {
|
||||
$paypal_adr = $this->testurl . '?test_ipn=1&';
|
||||
|
@ -506,7 +506,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
*/
|
||||
function process_payment( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( ! $this->form_submission_method ) {
|
||||
|
||||
|
@ -912,12 +912,12 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
list( $order_id, $order_key ) = $custom;
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( ! isset( $order->id ) ) {
|
||||
// We have an invalid $order_id, probably because invoice_prefix has changed
|
||||
$order_id = wc_get_order_id_by_order_key( $order_key );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
}
|
||||
|
||||
// Validate key
|
||||
|
|
|
@ -44,7 +44,7 @@ class WC_Shortcode_Checkout {
|
|||
|
||||
// Get the order to work out what we are showing
|
||||
$order_id = absint( $_GET['order'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( $order->has_status( 'pending' ) ) {
|
||||
$wp->query_vars['order-pay'] = absint( $_GET['order'] );
|
||||
|
@ -85,7 +85,7 @@ class WC_Shortcode_Checkout {
|
|||
|
||||
// Pay for existing order
|
||||
$order_key = $_GET[ 'key' ];
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order );
|
||||
|
||||
if ( ! current_user_can( 'pay_for_order', $order_id ) ) {
|
||||
|
@ -119,7 +119,7 @@ class WC_Shortcode_Checkout {
|
|||
|
||||
// Pay for order after checkout step
|
||||
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
$valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order );
|
||||
|
||||
if ( $order->id == $order_id && $order->order_key == $order_key ) {
|
||||
|
@ -186,7 +186,7 @@ class WC_Shortcode_Checkout {
|
|||
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
|
||||
|
||||
if ( $order_id > 0 ) {
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
if ( $order->order_key != $order_key )
|
||||
unset( $order );
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ class WC_Shortcode_My_Account {
|
|||
private static function view_order( $order_id ) {
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( ! current_user_can( 'view_order', $order_id ) ) {
|
||||
echo '<div class="woocommerce-error">' . __( 'Invalid order.', 'woocommerce' ) . ' <a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ).'" class="wc-forward">'. __( 'My Account', 'woocommerce' ) .'</a>' . '</div>';
|
||||
|
@ -118,7 +118,7 @@ class WC_Shortcode_My_Account {
|
|||
|
||||
wc_get_template( 'myaccount/view-order.php', array(
|
||||
'status' => $status, // @deprecated 2.2
|
||||
'order' => new WC_Order( $order_id ),
|
||||
'order' => get_order( $order_id ),
|
||||
'order_id' => $order_id
|
||||
) );
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class WC_Shortcode_Order_Tracking {
|
|||
|
||||
} else {
|
||||
|
||||
$order = new WC_Order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );
|
||||
$order = get_order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );
|
||||
|
||||
if ( $order->id && $order_email ) {
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ function wc_clear_cart_after_payment() {
|
|||
$order_key = '';
|
||||
|
||||
if ( $order_id > 0 ) {
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( $order->order_key == $order_key ) {
|
||||
WC()->cart->empty_cart();
|
||||
|
@ -130,7 +130,7 @@ function wc_clear_cart_after_payment() {
|
|||
|
||||
if ( WC()->session->order_awaiting_payment > 0 ) {
|
||||
|
||||
$order = new WC_Order( WC()->session->order_awaiting_payment );
|
||||
$order = get_order( WC()->session->order_awaiting_payment );
|
||||
|
||||
if ( $order->id > 0 ) {
|
||||
// If the order has not failed, or is not pending, the order must have gone through
|
||||
|
|
|
@ -31,6 +31,17 @@ function wc_get_order_statuses() {
|
|||
return apply_filters( 'wc_order_statuses', $order_statuses );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function for returning orders, uses the WC_Order_Factory class.
|
||||
*
|
||||
* @param mixed $the_order Post object or post ID of the order.
|
||||
* @param array $args (default: array()) Contains all arguments to be used to get this order.
|
||||
* @return WC_Order
|
||||
*/
|
||||
function get_order( $the_order = false, $args = array() ) {
|
||||
return WC()->order_factory->get_order( $the_order, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the nice name for an orer status
|
||||
* @param string $status
|
||||
|
@ -135,7 +146,7 @@ function wc_downloadable_product_permissions( $order_id ) {
|
|||
return; // Only do this once
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( $order->has_status( 'processing' ) && get_option( 'woocommerce_downloads_grant_access_after_payment' ) == 'no' ) {
|
||||
return;
|
||||
|
@ -312,7 +323,7 @@ function wc_cancel_unpaid_orders() {
|
|||
|
||||
if ( $unpaid_orders ) {
|
||||
foreach ( $unpaid_orders as $unpaid_order ) {
|
||||
$order = new WC_Order( $unpaid_order );
|
||||
$order = get_order( $unpaid_order );
|
||||
|
||||
if ( apply_filters( 'woocommerce_cancel_unpaid_order', true, $order ) )
|
||||
$order->update_status( 'cancelled', __( 'Unpaid order cancelled - time limit reached.', 'woocommerce' ) );
|
||||
|
|
|
@ -198,7 +198,7 @@ function wc_update_new_customer_past_orders( $customer_id ) {
|
|||
*/
|
||||
function wc_paying_customer( $order_id ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
|
||||
if ( $order->user_id > 0 ) {
|
||||
update_user_meta( $order->user_id, 'paying_customer', 1 );
|
||||
|
@ -278,7 +278,7 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
|
|||
switch ( $caps[0] ) {
|
||||
case 'view_order' :
|
||||
$user_id = $args[1];
|
||||
$order = new WC_Order( $args[2] );
|
||||
$order = get_order( $args[2] );
|
||||
|
||||
if ( $user_id == $order->user_id ) {
|
||||
$allcaps['view_order'] = true;
|
||||
|
@ -295,14 +295,14 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
|
|||
break;
|
||||
}
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
if ( $user_id == $order->user_id || empty( $order->user_id ) ) {
|
||||
$allcaps['pay_for_order'] = true;
|
||||
}
|
||||
break;
|
||||
case 'order_again' :
|
||||
$user_id = $args[1];
|
||||
$order = new WC_Order( $args[2] );
|
||||
$order = get_order( $args[2] );
|
||||
|
||||
if ( $user_id == $order->user_id ) {
|
||||
$allcaps['order_again'] = true;
|
||||
|
@ -310,7 +310,7 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
|
|||
break;
|
||||
case 'cancel_order' :
|
||||
$user_id = $args[1];
|
||||
$order = new WC_Order( $args[2] );
|
||||
$order = get_order( $args[2] );
|
||||
|
||||
if ( $user_id == $order->user_id ) {
|
||||
$allcaps['cancel_order'] = true;
|
||||
|
@ -418,7 +418,7 @@ function wc_get_customer_available_downloads( $customer_id ) {
|
|||
foreach ( $results as $result ) {
|
||||
if ( ! $order || $order->id != $result->order_id ) {
|
||||
// new order
|
||||
$order = new WC_Order( $result->order_id );
|
||||
$order = get_order( $result->order_id );
|
||||
$_product = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ if ( $customer_orders ) : ?>
|
|||
|
||||
<tbody><?php
|
||||
foreach ( $customer_orders as $customer_order ) {
|
||||
$order = new WC_Order();
|
||||
$order = get_order();
|
||||
$order->populate( $customer_order );
|
||||
$item_count = $order->get_item_count();
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
|
||||
global $woocommerce;
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
$order = get_order( $order_id );
|
||||
?>
|
||||
<h2><?php _e( 'Order Details', 'woocommerce' ); ?></h2>
|
||||
<table class="shop_table order_details">
|
||||
|
|
|
@ -76,6 +76,11 @@ final class WooCommerce {
|
|||
*/
|
||||
public $customer = null;
|
||||
|
||||
/**
|
||||
* @var WC_Order_Factory $order_factory
|
||||
*/
|
||||
public $order_factory = null;
|
||||
|
||||
/**
|
||||
* Main WooCommerce Instance
|
||||
*
|
||||
|
@ -279,6 +284,7 @@ final class WooCommerce {
|
|||
|
||||
// Include abstract classes
|
||||
include_once( 'includes/abstracts/abstract-wc-product.php' ); // Products
|
||||
include_once( 'includes/abstracts/abstract-wc-order.php' ); // Orders
|
||||
include_once( 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
|
||||
include_once( 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
|
||||
include_once( 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
|
||||
|
@ -362,6 +368,7 @@ final class WooCommerce {
|
|||
|
||||
// Load class instances
|
||||
$this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances
|
||||
$this->order_factory = new WC_Order_Factory(); // Order Factory to create new order instances
|
||||
$this->countries = new WC_Countries(); // Countries class
|
||||
$this->integrations = new WC_Integrations(); // Integrations class
|
||||
|
||||
|
|
Loading…
Reference in New Issue