How to manage stock and backorders in WooCommerce

WooCommerce allows to manage inventory for each product and product variations. Enable the “Manage Stock?” option to make the following visible:

Screen Shot

Screenshot of the inventory tab of a WooCommerce Simple product.

Stock control

WooCommerce has two options used to manage stock.

  • The stock quantity which counts the number of available items.
  • The stock status which manages the availability of the product on the front end.

In the default configuration backorders are not allowed. This ensues the following behaviour:

  • Setting the stock quantity to zero or having it fall to zero due to a sale automatically sets the stock status to “Out of stock”. This is then reflected in your front end like so:

Screen Shot

backorders = do not allow
stock quantity = 0
stock status automatically set to “out of stock” due to stock quantity below 1

This is how most stores handles this. Now lets add the backorder option to the configuration and play through all three possible options.

Variable products

Contrary to simple products the standard inventory tab is not used. This means that despite active stock control your inventory tab for your variable product will have:

  • “Manage stock?” unchecked
  • No stock quantity
  • No SKU
  • No relevant Stock status

No need to be alarmed by this. Instead these are now located with each product variation:

Managing backorders

As long as backorders are set to “Do not allow”, the following is true: 

  • The product cannot be ordered from the front end.
  • The stock quantity can be set to negative number, for example “-3” via the product edit screen in the backend.
  • An order added manually via the WooCommerce backend will not decrease the stock further automatically. Instead you need to edit the order and manually decrease the stock by clicking on the line item and then use the “Reduce stock” button:

Screen Shot

  • Reducing stock manually via “Reduce Stock” will set the stock below zero to negative values. For example from -2 to -3. Stock changes are normally recorded in the order notes. Reducing the stock like this with these options does not record the action in the order notes.

If you want to keep accepting orders and have your customers pay for them in advance, you need to allow backorders.

Setting the backorders option to “Allow, but notify customer” changes the scenario. Now the following is true: 

  • Changing the stock value in the backend now does not set the stock status. Because WooCommerce is now prepared to keep selling regardless of the inventory count, both values are not linked any longer.
  • The product can be purchased from the front end. There is a notice above the add to cart button that signals that this is a backorder:

Screen Shot

backorders =Allow, but notify customer
stock quantity = 0
stock status = in stock

  • Backorders only are possible for as long as the stock status is “in stock”. Setting the product to out of stock will again block purchases and display “out of stock”.
  • Customers can purchase the product and checkout as normal. They pay in full and every purchase will decrease the stock. The order will indicate that it is a backorder in the cart and checkout.

Screen Shot

Thank you page indicating the backorder status.

  • Viewing the order in the backend will provide similar information:

Screen Shot

  • Stock reductions are also recorded in the order notes:

Screen Shot

Setting the backorders option to “Allow” produces the same scenario without the backorder labels.

The product is basically shown and treated as “in stock”.  But the stock can be negative. However your customers get no signal that they are ordering on backorder.

The above mentioned plugin will still correctly count all backorders since WooCommerce adds a meta information to the order that flags it as a backorder.

The only difference here is that this information is output nowhere. It allows for “invisible” / discreet backorder function.

How to show a notice for when WooCommerce backorders are allowed

Here is a code snippet that allows you to add notices for when backorders are (not) allowed:

//output with add to cart button
add_action( 'woocommerce_after_add_to_cart_form', 'custom_notice_for_backorders_allowed' );

function custom_notice_for_backorders_allowed() 
    {
        //instantinate product object
        global $product;
        
        //check if backorders are allowed
        if ( $product->backorders_allowed() ) 
           {
            ?>
            Backorders allowed: Put some text and <a href="#">links here.</a>
            <?php
        }
        
    }


//output after product title
add_action( 'woocommerce_single_product_summary', 'custom_notice_for_backorders_not_allowed' );

function custom_notice_for_backorders_not_allowed() 
    {
        global $product;
        
        //check if backorders are not allowed
        if ( ! $product->backorders_allowed() ) 
           {    
               ?>
            Backorders not allowed: Put some text and <a href="#">links here.</a>
            <?php
        }
        
    }

Here is how to handle these kind of code snippets.

Third party applications

The relationship described above where stock quantity triggers stock status and backorders define their behaviour only works properly when the WordPress backend is used to do so, or if a purchase is made.

Keep in mind that values such as stock quantity, stock status and backorders can also be managed by third party applications via API calls and / or CLI commands. In which case the hooks that link stock quantity and stock status and other checks are bypassed.

This means a third party application (such as your fulfillments company) can possibly set a product to wonky configurations that are normally automatically checked and corrected by WooCommerce.

For example:
stock quantity = 0
stock status = in stock.
backorders = Do not allow

If you run into inconsistent stock behaviour then chances are that external commands only pass a value for stock quantity while neglecting to pass the stock status as well. Oftentimes the backorder values are completely ignored.

It is good practice to account for all three values whenever such a command is sent to WooCommerce. Check with your third party and ensure that the code that manages your WooCommerce stock does account for all three options so that wonky configurations do not come to pass.

 

Image credits: Header image doodle by Anna Werner for wp4e.de

Related Posts

Powered By Related Posts for WordPress

One Reply to “How to manage stock and backorders in WooCommerce”

Leave a Reply

Your email address will not be published. Required fields are marked *