• Resolved Sunny Hossain

    (@ictsamidul21)


    I’m using custom quantity. But this program is not working, I don’t know that my code is correct. But I want stock quantity updated by custom value, Help me, please

    function action_woocommerce_order_status_completed( $order_id ) {
        // The WC_Order instance Object
        $order = wc_get_order( $order_id );
        
        // Is an order
        if ( is_a( $order, 'WC_Order' ) ) {
            // Loop through order items
            foreach ( $order->get_items() as $key => $item ) {
                // The WC_Product instance Object
                $product = $item->get_product();
    
               
                    // NOT in stock
                    if ( ! $product->is_in_stock() ) {
                        // Update a product's stock amount
                        wc_update_product_stock( $product, 10, 'set', 'false' );
    
                        // Update a product's stock status
                        wc_update_product_stock_status( $product->get_id(), 'instock' );
                    }
            }   
        }
    }
    add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Stock update with custom value’ is closed to new replies.