• Resolved Chad Reitsma

    (@chadreitsma)


    Hey guys,

    Do you have a filter to disable stock reduction when creating a quote? One of our client’s uses this quite heavily, but they only want the stock reduced when it’s converted to an invoice.

    Any help would be appreciated! ??

    Cheers,
    C.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support MeganSupport

    (@megan891)

    Hi @chadreitsma

    Sliced Invoices doesn’t have any stock keeping feature. If you are using WooCommerce stock management is handled entirely by WooCommerce. It may be adjustable in the WooCommerce settings, but we’re not 100% sure. Maybe WooCommerce has some hook where you can tell it to reduce stock only for certain order statuses… for example to make it ignore the order when the status is “quote”.

    If you need any further assistance please log a support ticket via our website here https://slicedinvoices.com/support-ticket/

    Thanks in advance,

    Sliced Invoices

    Thread Starter Chad Reitsma

    (@chadreitsma)

    Ah, that makes sense. I think I have seen that filter before, I’ll do some more digging. Appreciate the reply/direction!

    Cheers,
    C.

    Plugin Support MeganSupport

    (@megan891)

    No problem @chadreitsma!

    Hi @chadreitsma,
    Did you find the solution; I’m looking for the same thing.
    It seem logical not to discount stock for a quote.
    Thanks,
    Ana

    • This reply was modified 4 years, 2 months ago by Ana Pascual.
    Thread Starter Chad Reitsma

    (@chadreitsma)

    @anoni
    Hi Ana,

    I have solved this by restoring the stock levels of the order IF the order transitions from the “pending” status to the “quote” status (as it does when you manually create an order/quote in the admin panel).

    This assumes you are letting WooCom manage your stock – as woocom will automatically reduce stock when you save the order, this will restore the stock levels as it transitions from the Pending -> Quote status.

    It will also reduce the stock levels if you then transition the Quote status to invoice. You can adjust the logic as needed….

    Add this to your child-theme’s functions.php file to test:

    add_action('woocommerce_order_status_changed', 'inet_order_status_changed', 10, 4);
    function inet_order_status_changed($order_id, $status_transition_from, $status_transition_to, $order) {
        
        //If transitioning from pending to quote, woocom already subtracted stock, restore it...
        if ($status_transition_from == "pending" && $status_transition_to == "quote") {
            foreach ($order->get_items() as $item_id => $item) {
                $product = $item->get_product();
                $qty = $item->get_quantity(); // Get the item quantity
                wc_update_product_stock($product, $qty, 'increase');
                $order->add_order_note( 'Stock levels restored for Quote.' );
            } 
        }
        
        //If transitioning from quote to invoice, we restored the stock using the function above - so now we have to reduce it again!
        if ($status_transition_from == "quote" && $status_transition_to == "invoice") {
            foreach ($order->get_items() as $item_id => $item) {
                $product = $item->get_product();
                $qty = $item->get_quantity(); // Get the item quantity
                wc_update_product_stock($product, $qty, 'decrease');
                $order->add_order_note( 'Stock levels reduced for Quote->Invoice transition.' );
            } 
        }   
    }
    • This reply was modified 4 years, 2 months ago by Chad Reitsma.

    Hi Chad @chadreitsma,
    Many many thanks!!
    It has worked perfectly
    I’m very grateful!
    Cheers,

    Ana

    Thread Starter Chad Reitsma

    (@chadreitsma)

    @anoni
    Happy to help!

    I just realized my code will create multiple “Notes” if you have multiple items in the order. To fix that just move the $order->add_order_note line outside of the foreach loop.

    Cheers,
    C.

    Hi @chadreitsma !
    Many, many thanks for advice and give a solution!!!
    Ana

    Plugin Support MeganSupport

    (@megan891)

    Thanks for the help @chadreitsma!

    @anoni please let us know if you need any additional assistance – if you do you are more than welcome to log a support ticket via our website here https://slicedinvoices.com/support-ticket/

    Kind regards,

    Sliced Invoices Support

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Don’t reduce inventory when creating a quote’ is closed to new replies.