Home > Enterprise >  WooCommerce increase stock button on order page
WooCommerce increase stock button on order page

Time:09-18

Does anyone have (or know of) a PHP code snippet solution to add automation say a checkbox to increase stock by quote list or bring back the original increase stock button in the order page; before sending out a quote ?

I have searched many days and hours for a code solution or a Plugin => Nothing.

I believe WooCommerce once used to have this button in the orders page but it is now not there, I am on Woo5.6.0, WP5.8 and PHP7.4

Thanks in advance.

CodePudding user response:

So.. After re-posting my question again and reducing it to simplify and add focus, after I think a robot response closed my original question.

I looked at the suggestions that came up and "would you believe it" the post below was in the suggestion list.. I had not seen this before.

Increase stock (not decrease) after completed WooCommerce orders?

I had to test and change the call adapt the code a little to fit my store model..

I now have a working safe way of targeting only the stock from a quote list and only elevating the stock by the quote list amount (quantity) when I send out a quote.

The only downside to this is if another client comes along and sees the commission in stock they could place it in their basket and then it would not match the original quote sent out.

"Code to develop another time to find a way to reserve that elevated and allocated stock".

I did this after thinking about how to only trigger an action for a sent quote.

So a deep dive into Yiths Request a quote code to find the class where it changed the WooCommerce order status and came up with this.

Thanks to @loictheaztec he was responsible for this inspiration.

// Increase stock on pending quote order status - An experiment "ywraq-pending"

add_action( 'woocommerce_order_status_ywraq-pending', 'action_on_quote_sent' , 10, 1 );
function action_on_quote_sent( $order_id )
{
    // Get an instance of the order object
    $order = wc_get_order( $order_id );

    // Iterating though each order items
    foreach ( $order->get_items() as $item_id => $item_values ) {

        // Item quantity
        $item_qty = $item_values['qty'];

        // getting the product ID (Simple and variable products)
        $product_id = $item_values['variation_id'];
        if( $product_id == 0 || empty($product_id) ) $product_id = $item_values['product_id'];

        // Get an instance of the product object
        $product = wc_get_product( $product_id );

        // Get the stock quantity of the product
        $product_stock = $product->get_stock_quantity();

        // Increase back the stock quantity
        wc_update_product_stock( $product, $item_qty, 'increase' );
    }
}
  • Related