Reduce stock and other notices
This commit is contained in:
parent
8d58febaf8
commit
f4a4f6c361
|
@ -296,35 +296,37 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
*/
|
||||
protected function save_items() {
|
||||
foreach ( $this->_items as $item_group => $items ) {
|
||||
foreach ( $items as $item_key => $item ) {
|
||||
$item->set_order_id( $this->get_id() );
|
||||
$item_id = $item->save();
|
||||
if ( is_array( $items ) ) {
|
||||
foreach ( $items as $item_key => $item ) {
|
||||
$item->set_order_id( $this->get_id() );
|
||||
$item_id = $item->save();
|
||||
|
||||
// If ID changed (new item saved to DB)...
|
||||
if ( $item_id !== $item_key ) {
|
||||
$this->_items[ $item_group ][ $item_id ] = $item;
|
||||
unset( $this->_items[ $item_group ][ $item_key ] );
|
||||
// If ID changed (new item saved to DB)...
|
||||
if ( $item_id !== $item_key ) {
|
||||
$this->_items[ $item_group ][ $item_id ] = $item;
|
||||
unset( $this->_items[ $item_group ][ $item_key ] );
|
||||
|
||||
// Legacy action handler
|
||||
switch ( $item_group ) {
|
||||
case 'fee_lines' :
|
||||
if ( has_action( 'woocommerce_add_order_fee_meta' ) && isset( $item->legacy_fee, $item->legacy_fee_key ) ) {
|
||||
_deprecated_function( 'Action: woocommerce_add_order_fee_meta', '2.7', 'Use woocommerce_new_order_item action instead.' );
|
||||
do_action( 'woocommerce_add_order_fee_meta', $this->get_id(), $item_id, $item->legacy_fee, $item->legacy_fee_key );
|
||||
}
|
||||
break;
|
||||
case 'shipping_lines' :
|
||||
if ( has_action( 'woocommerce_add_shipping_order_item' ) && isset( $item->legacy_package_key ) ) {
|
||||
_deprecated_function( 'Action: woocommerce_add_shipping_order_item', '2.7', 'Use woocommerce_new_order_item action instead.' );
|
||||
do_action( 'woocommerce_add_shipping_order_item', $item_id, $item->legacy_package_key );
|
||||
}
|
||||
break;
|
||||
case 'line_items' :
|
||||
if ( has_action( 'woocommerce_add_order_item_meta' ) && isset( $item->legacy_values, $item->legacy_cart_item_key ) ) {
|
||||
_deprecated_function( 'Action: woocommerce_add_order_item_meta', '2.7', 'Use woocommerce_new_order_item action instead.' );
|
||||
do_action( 'woocommerce_add_order_item_meta', $item_id, $item->legacy_values, $item->legacy_cart_item_key );
|
||||
}
|
||||
break;
|
||||
// Legacy action handler
|
||||
switch ( $item_group ) {
|
||||
case 'fee_lines' :
|
||||
if ( has_action( 'woocommerce_add_order_fee_meta' ) && isset( $item->legacy_fee, $item->legacy_fee_key ) ) {
|
||||
_deprecated_function( 'Action: woocommerce_add_order_fee_meta', '2.7', 'Use woocommerce_new_order_item action instead.' );
|
||||
do_action( 'woocommerce_add_order_fee_meta', $this->get_id(), $item_id, $item->legacy_fee, $item->legacy_fee_key );
|
||||
}
|
||||
break;
|
||||
case 'shipping_lines' :
|
||||
if ( has_action( 'woocommerce_add_shipping_order_item' ) && isset( $item->legacy_package_key ) ) {
|
||||
_deprecated_function( 'Action: woocommerce_add_shipping_order_item', '2.7', 'Use woocommerce_new_order_item action instead.' );
|
||||
do_action( 'woocommerce_add_shipping_order_item', $item_id, $item->legacy_package_key );
|
||||
}
|
||||
break;
|
||||
case 'line_items' :
|
||||
if ( has_action( 'woocommerce_add_order_item_meta' ) && isset( $item->legacy_values, $item->legacy_cart_item_key ) ) {
|
||||
_deprecated_function( 'Action: woocommerce_add_order_item_meta', '2.7', 'Use woocommerce_new_order_item action instead.' );
|
||||
do_action( 'woocommerce_add_order_item_meta', $item_id, $item->legacy_values, $item->legacy_cart_item_key );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -831,18 +833,29 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
* @return Array of WC_Order_item
|
||||
*/
|
||||
public function get_items( $types = 'line_item' ) {
|
||||
$type_to_group = array(
|
||||
'line_item' => 'line_items',
|
||||
'tax' => 'tax_lines',
|
||||
'shipping' => 'shipping_lines',
|
||||
'fee' => 'fee_lines',
|
||||
'coupon' => 'coupon_lines',
|
||||
);
|
||||
|
||||
if ( is_array( $types ) ) {
|
||||
foreach ( $types as $type ) {
|
||||
if ( is_null( $this->_items[ $type ] ) ) {
|
||||
$this->_items[ $type ] = $this->get_items_from_db( $type );
|
||||
if ( isset( $type_to_group[ $type ] ) && is_null( $this->_items[ $type_to_group[ $type ] ] ) ) {
|
||||
$this->_items[ $type_to_group[ $type ] ] = $this->get_items_from_db( $type );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$items = array();
|
||||
$types = (array) $types;
|
||||
|
||||
foreach ( $types as $type ) {
|
||||
$items = array_merge( $items, $this->_items[ $type ] );
|
||||
if ( isset( $type_to_group[ $type ] ) && isset( $this->_items[ $type_to_group[ $type ] ] ) ) {
|
||||
$items = array_merge( $items, $this->_items[ $type_to_group[ $type ] ] );
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_order_get_items', $items, $this );
|
||||
|
|
|
@ -128,7 +128,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
|
|||
'id' => $order->get_id(),
|
||||
'parent_id' => $post->post_parent,
|
||||
'status' => $order->get_status(),
|
||||
'order_key' => $order->order_key,
|
||||
'order_key' => $order->get_order_key(),
|
||||
'number' => $order->get_order_number(),
|
||||
'currency' => $order->get_currency(),
|
||||
'version' => $order->order_version,
|
||||
|
|
|
@ -161,7 +161,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$order_data = array(
|
||||
'id' => $order->get_id(),
|
||||
'order_number' => $order->get_order_number(),
|
||||
'order_key' => $order->order_key,
|
||||
'order_key' => $order->get_order_key(),
|
||||
'created_at' => $this->server->format_datetime( $order_post->post_date_gmt ),
|
||||
'updated_at' => $this->server->format_datetime( $order_post->post_modified_gmt ),
|
||||
'completed_at' => $this->server->format_datetime( $order->completed_date, true ),
|
||||
|
|
|
@ -288,7 +288,7 @@ class WC_Form_Handler {
|
|||
$order_id = absint( $wp->query_vars['order-pay'] );
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( $order->get_id() == $order_id && $order->order_key == $order_key && $order->needs_payment() ) {
|
||||
if ( $order->get_id() == $order_id && $order->get_order_key() == $order_key && $order->needs_payment() ) {
|
||||
|
||||
do_action( 'woocommerce_before_pay_action', $order );
|
||||
|
||||
|
@ -660,7 +660,7 @@ class WC_Form_Handler {
|
|||
|
||||
if ( $order->has_status( 'cancelled' ) ) {
|
||||
// Already cancelled - take no action
|
||||
} elseif ( $user_can_cancel && $order_can_cancel && $order->get_id() === $order_id && $order->order_key === $order_key ) {
|
||||
} elseif ( $user_can_cancel && $order_can_cancel && $order->get_id() === $order_id && $order->get_order_key() === $order_key ) {
|
||||
|
||||
// Cancel the order + restore stock
|
||||
$order->cancel_order( __('Order cancelled by customer.', 'woocommerce' ) );
|
||||
|
|
|
@ -337,7 +337,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
|
|||
$order->update_status( 'on-hold', __( 'Awaiting BACS payment', 'woocommerce' ) );
|
||||
|
||||
// Reduce stock levels
|
||||
$order->reduce_order_stock();
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
|
||||
// Remove cart
|
||||
WC()->cart->empty_cart();
|
||||
|
|
|
@ -116,7 +116,7 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
|
|||
$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
|
||||
|
||||
// Reduce stock levels
|
||||
$order->reduce_order_stock();
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
|
||||
// Remove cart
|
||||
WC()->cart->empty_cart();
|
||||
|
|
|
@ -203,7 +203,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
|||
$order->update_status( apply_filters( 'woocommerce_cod_process_payment_order_status', $order->has_downloadable_item() ? 'on-hold' : 'processing', $order ), __( 'Payment to be made upon delivery.', 'woocommerce' ) );
|
||||
|
||||
// Reduce stock levels
|
||||
$order->reduce_order_stock();
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
|
||||
// Remove cart
|
||||
WC()->cart->empty_cart();
|
||||
|
|
|
@ -77,7 +77,7 @@ class WC_Gateway_Paypal_Request {
|
|||
'paymentaction' => $this->gateway->get_option( 'paymentaction' ),
|
||||
'bn' => 'WooThemes_Cart',
|
||||
'invoice' => $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(),
|
||||
'custom' => json_encode( array( 'order_id' => $order->get_id(), 'order_key' => $order->order_key ) ),
|
||||
'custom' => json_encode( array( 'order_id' => $order->get_id(), 'order_key' => $order->get_order_key() ) ),
|
||||
'notify_url' => $this->notify_url,
|
||||
'first_name' => $order->get_billing_first_name(),
|
||||
'last_name' => $order->get_billing_last_name(),
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract class WC_Gateway_Paypal_Response {
|
|||
$order = wc_get_order( $order_id );
|
||||
}
|
||||
|
||||
if ( ! $order || $order->order_key !== $order_key ) {
|
||||
if ( ! $order || $order->get_order_key() !== $order_key ) {
|
||||
WC_Gateway_Paypal::log( 'Error: Order Keys do not match.' );
|
||||
return false;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ abstract class WC_Gateway_Paypal_Response {
|
|||
*/
|
||||
protected function payment_on_hold( $order, $reason = '' ) {
|
||||
$order->update_status( 'on-hold', $reason );
|
||||
$order->reduce_order_stock();
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
WC()->cart->empty_cart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
|
|||
}
|
||||
|
||||
// Reduce stock levels
|
||||
$order->reduce_order_stock();
|
||||
wc_reduce_stock_levels( $order_id );
|
||||
|
||||
// Remove cart
|
||||
WC()->cart->empty_cart();
|
||||
|
|
|
@ -90,7 +90,7 @@ class WC_Shortcode_Checkout {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( $order->get_id() == $order_id && $order->order_key == $order_key ) {
|
||||
if ( $order->get_id() == $order_id && $order->get_order_key() == $order_key ) {
|
||||
|
||||
if ( $order->needs_payment() ) {
|
||||
|
||||
|
@ -133,7 +133,7 @@ class WC_Shortcode_Checkout {
|
|||
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( $order->get_id() == $order_id && $order->order_key == $order_key ) {
|
||||
if ( $order->get_id() == $order_id && $order->get_order_key() == $order_key ) {
|
||||
|
||||
if ( $order->needs_payment() ) {
|
||||
|
||||
|
@ -200,7 +200,7 @@ class WC_Shortcode_Checkout {
|
|||
|
||||
if ( $order_id > 0 ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( $order->order_key != $order_key ) {
|
||||
if ( $order->get_order_key() != $order_key ) {
|
||||
$order = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ function wc_clear_cart_after_payment() {
|
|||
if ( $order_id > 0 ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( $order->order_key === $order_key ) {
|
||||
if ( $order->get_order_key() === $order_key ) {
|
||||
WC()->cart->empty_cart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,7 +432,7 @@ function wc_downloadable_file_permission( $download_id, $product_id, $order, $qt
|
|||
'user_id' => absint( $order->get_user_id() ),
|
||||
'user_email' => $user_email,
|
||||
'order_id' => $order->get_id(),
|
||||
'order_key' => $order->order_key,
|
||||
'order_key' => $order->get_order_key(),
|
||||
'downloads_remaining' => $limit,
|
||||
'access_granted' => current_time( 'mysql' ),
|
||||
'download_count' => 0
|
||||
|
|
|
@ -456,7 +456,7 @@ function wc_get_customer_available_downloads( $customer_id ) {
|
|||
'product_id' => $product_id,
|
||||
'download_name' => $download_name,
|
||||
'order_id' => $order->get_id(),
|
||||
'order_key' => $order->order_key,
|
||||
'order_key' => $order->get_order_key(),
|
||||
'downloads_remaining' => $result->downloads_remaining,
|
||||
'access_expires' => $result->access_expires,
|
||||
'file' => $download_file
|
||||
|
|
|
@ -23,10 +23,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<header><h2><?php _e( 'Customer Details', 'woocommerce' ); ?></h2></header>
|
||||
|
||||
<table class="shop_table customer_details">
|
||||
<?php if ( $order->customer_note ) : ?>
|
||||
<?php if ( $order->get_customer_note() ) : ?>
|
||||
<tr>
|
||||
<th><?php _e( 'Note:', 'woocommerce' ); ?></th>
|
||||
<td><?php echo wptexturize( $order->customer_note ); ?></td>
|
||||
<td><?php echo wptexturize( $order->get_customer_note() ); ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
Loading…
Reference in New Issue