/**
  * Reduce stock levels
  */
 public function reduce_order_stock()
 {
     // Reduce stock levels and do any other actions with products in the cart
     if (sizeof($this->items) > 0) {
         foreach ($this->items as $item) {
             if ($item['id'] > 0) {
                 $_product = $this->get_product_from_item($item);
                 if ($_product instanceof fflcommerce_product_variation) {
                     if ($_product->stock == '-9999999') {
                         // the parent product is used for variation stock tracking
                         $_product = new fflcommerce_product($_product->id);
                     }
                 }
                 if ($_product->exists && $_product->managing_stock()) {
                     $old_stock = $_product->stock;
                     $new_quantity = $_product->reduce_stock($item['qty']);
                     $this->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'fflcommerce'), $item['id'], $old_stock, $new_quantity));
                     if ($new_quantity < 0) {
                         do_action('fflcommerce_product_on_backorder_notification', $this->id, $_product, $item['qty']);
                     }
                     // stock status notifications
                     if (self::get_options()->get('fflcommerce_notify_no_stock') == 'yes' && self::get_options()->get('fflcommerce_notify_no_stock_amount') >= 0 && self::get_options()->get('fflcommerce_notify_no_stock_amount') >= $new_quantity) {
                         do_action('fflcommerce_no_stock_notification', $_product);
                     } elseif (self::get_options()->get('fflcommerce_notify_low_stock') == 'yes' && self::get_options()->get('fflcommerce_notify_low_stock_amount') && self::get_options()->get('fflcommerce_notify_low_stock_amount') >= $new_quantity) {
                         do_action('fflcommerce_low_stock_notification', $_product);
                     }
                 }
             }
         }
     }
     $this->add_order_note(__('Order item stock reduced successfully.', 'fflcommerce'));
 }