Revert "Add adjust stock option to order class when adding items"

This reverts commit 4a0447a150.
This commit is contained in:
Mike Jolley 2019-01-03 11:16:06 +00:00
parent 184b121eb8
commit 282edab5d6
1 changed files with 1 additions and 19 deletions

View File

@ -1139,11 +1139,10 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* @param WC_Product $product Product object. * @param WC_Product $product Product object.
* @param int $qty Quantity to add. * @param int $qty Quantity to add.
* @param array $args Args for the added product. * @param array $args Args for the added product.
* @param bool $adjust_stock True or false. Should the product stock also be reduced whilst adding to the order?
* @return int * @return int
* @throws WC_Data_Exception Exception thrown if the item cannot be added to the cart. * @throws WC_Data_Exception Exception thrown if the item cannot be added to the cart.
*/ */
public function add_product( $product, $qty = 1, $args = array(), $adjust_stock = false ) { public function add_product( $product, $qty = 1, $args = array() ) {
if ( $product ) { if ( $product ) {
$default_args = array( $default_args = array(
'name' => $product->get_name(), 'name' => $product->get_name(),
@ -1180,25 +1179,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$item->set_props( $args ); $item->set_props( $args );
$item->set_backorder_meta(); $item->set_backorder_meta();
$item->set_order_id( $this->get_id() ); $item->set_order_id( $this->get_id() );
if ( $adjust_stock && $product && $product->managing_stock() ) {
$item_name = $product->get_formatted_name();
$new_stock = wc_update_product_stock( $product, $item->get_quantity(), 'decrease' );
if ( is_wp_error( $new_stock ) ) {
/* translators: %s item name. */
$this->add_order_note( sprintf( __( 'Unable to reduce stock for item %s.', 'woocommerce' ), $item_name ) );
} else {
/* translators: %1$s: item name, %2$s stock change */
$this->add_order_note( sprintf( __( '%1$s stock reduced %2$s.', 'woocommerce' ), $item_name, $new_stock . '→' . ( $new_stock - $item->get_quantity() ) ) );
}
$item->add_meta_data( '_reduced_stock', $item->get_quantity(), true );
}
$item->save(); $item->save();
$this->add_item( $item ); $this->add_item( $item );
wc_do_deprecated_action( 'woocommerce_order_add_product', array( $this->get_id(), $item->get_id(), $product, $qty, $args ), '3.0', 'woocommerce_new_order_item action instead' ); wc_do_deprecated_action( 'woocommerce_order_add_product', array( $this->get_id(), $item->get_id(), $product, $qty, $args ), '3.0', 'woocommerce_new_order_item action instead' );
delete_transient( 'wc_order_' . $this->get_id() . '_needs_processing' ); delete_transient( 'wc_order_' . $this->get_id() . '_needs_processing' );
return $item->get_id(); return $item->get_id();