/**
 * When a payment is complete, we can reduce stock levels for items within an order.
 * @since 2.7.0
 * @param int $order_id
 */
function wc_maybe_reduce_stock_levels($order_id)
{
    $data_store = WC_Data_Store::load('order');
    if (apply_filters('woocommerce_payment_complete_reduce_order_stock', !$data_store->get_stock_reduced($order_id), $order_id)) {
        wc_reduce_stock_levels($order_id);
        $data_store->set_stock_reduced($order_id, true);
    }
}
 /**
  * Process the payment and return the result.
  *
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     $order = wc_get_order($order_id);
     // Mark as on-hold (we're awaiting the cheque)
     $order->update_status('on-hold', _x('Awaiting check payment', 'Check payment method', 'woocommerce'));
     // Reduce stock levels
     wc_reduce_stock_levels($order_id);
     // Remove cart
     WC()->cart->empty_cart();
     // Return thankyou redirect
     return array('result' => 'success', 'redirect' => $this->get_return_url($order));
 }
 /**
  * Process the payment and return the result.
  *
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     $order = wc_get_order($order_id);
     // Mark as processing or on-hold (payment won't be taken until delivery)
     $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
     wc_reduce_stock_levels($order_id);
     // Remove cart
     WC()->cart->empty_cart();
     // Return thankyou redirect
     return array('result' => 'success', 'redirect' => $this->get_return_url($order));
 }
 /**
  * Process the pre-order.
  *
  * @param WC_Order $order
  * @param string   $cart_token
  * @uses  Simplify_ApiException
  * @uses  Simplify_BadRequestException
  * @return array
  */
 protected function process_pre_order($order, $cart_token = '')
 {
     if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order->get_id())) {
         try {
             if ($order->get_total() * 100 < 50) {
                 $error_msg = __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce');
                 throw new Simplify_ApiException($error_msg);
             }
             if (empty($cart_token)) {
                 $error_msg = __('Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'woocommerce');
                 if ('yes' == $this->sandbox) {
                     $error_msg .= ' ' . __('Developers: Please make sure that you\'re including jQuery and there are no JavaScript errors on the page.', 'woocommerce');
                 }
                 throw new Simplify_ApiException($error_msg);
             }
             // Create customer
             $customer = Simplify_Customer::createCustomer(array('token' => $cart_token, 'email' => $order->get_billing_email(), 'name' => trim($order->get_formatted_billing_full_name()), 'reference' => $order->get_id()));
             if (is_object($customer) && '' != $customer->id) {
                 $customer_id = wc_clean($customer->id);
                 // Store the customer ID in the order
                 update_post_meta($order->get_id(), '_simplify_customer_id', $customer_id);
             } else {
                 $error_msg = __('Error creating user in Simplify Commerce.', 'woocommerce');
                 throw new Simplify_ApiException($error_msg);
             }
             // Reduce stock levels
             wc_reduce_stock_levels($order_id);
             // Remove cart
             WC()->cart->empty_cart();
             // Is pre ordered!
             WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
             // Return thank you page redirect
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         } catch (Simplify_ApiException $e) {
             if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) {
                 foreach ($e->getFieldErrors() as $error) {
                     wc_add_notice($error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')', 'error');
                 }
             } else {
                 wc_add_notice($e->getMessage(), 'error');
             }
             return array('result' => 'fail', 'redirect' => '');
         }
     } else {
         return parent::process_standard_payments($order, $cart_token);
     }
 }
 /**
  * Hold order and add note.
  * @param  WC_Order $order
  * @param  string   $reason
  */
 protected function payment_on_hold($order, $reason = '')
 {
     $order->update_status('on-hold', $reason);
     wc_reduce_stock_levels($order_id);
     WC()->cart->empty_cart();
 }
/**
 * When a payment is complete, we can reduce stock levels for items within an order.
 * @since 2.7.0
 * @param int $order_id
 */
function wc_maybe_reduce_stock_levels($order_id)
{
    if (apply_filters('woocommerce_payment_complete_reduce_order_stock', !get_post_meta($order_id, '_order_stock_reduced', true), $order_id)) {
        wc_reduce_stock_levels($order_id);
        add_post_meta($order_id, '_order_stock_reduced', '1', true);
    }
}
 /**
  * Reduce stock levels for all line items in the order.
  * @deprecated 2.7.0
  */
 public function reduce_order_stock()
 {
     _deprecated_function('reduce_order_stock', '2.7', 'wc_reduce_stock_levels');
     wc_reduce_stock_levels($this->get_id());
 }