How to disable or remove stock notes from showing in WooCommerce Order edit screen

I have stock management enabled on my WooCommerce store as this is critical being that we sell physical goods and products that we stock in our warehouse. Everything about the inventory management works as we need it to, but because we have it enabled, we’re getting extra order notes displaying on the Edit Order screens of WooCommerce. This is causing extra data to be saved to our database and also gets based into QuickBooks as order notes that we just do not need to be there.

I’ve found in the core WooCommerce the function that is adding this order note, I’m just not sure how to remove it without modifying core files. I’m looking for some sort of way to disable or remove it with a hook, filter, or class extension that can be placed in my sites utility plugin.
Screenshot showing sidebar of Edit Order screen with numerous “stock reduced” messages displayed

Read More

The code is in the abstract-wc-order.php file (/woocommerce/abstracts/abstract-wc-order.php) starting at lines 2460:

if ( isset( $item['variation_id'] ) && $item['variation_id'] ) {
                        $this->add_order_note( sprintf( __( 'Item #%s variation #%s stock reduced from %s to %s.', 'woocommerce' ), $item['product_id'], $item['variation_id'], $new_stock + $qty, $new_stock) );
                    } else {
                        $this->add_order_note( sprintf( __( 'Item #%s stock reduced from %s to %s.', 'woocommerce' ), $item['product_id'], $new_stock + $qty, $new_stock) );
                    }

Related posts

1 comment

  1. You can grab the comment id and content via the wp_insert_comment action hook and delete it, which would likely prevent it from being sent to Quickbooks. Using a simple strpos match for "stock reduced from" we can check if the comment is for stock reduction.

    add_action('wp_insert_comment', 'remove_stock_comment', 10, 2);
    
    function remove_stock_comment($id, $comment) {
        if( strpos($comment->comment_content, 'stock reduced from') !== false ) {
            wp_delete_comment( $id );
        }
    }
    

    To further check whether the comment belongs to an order, you can get the comment’s POST ID and check its post_type.

    Note: I’m not sure whether this solution would break any other functionality, but this is the only solution I could come up with.

Comments are closed.