Website Building » WooCommerce » How Do I Change the Out of Stock Status in WooCommerce?

How Do I Change the Out of Stock Status in WooCommerce?

Last updated on December 22, 2022 @ 6:30 am

If you are using WooCommerce to sell products on your WordPress site, you may have noticed that there is no obvious way to change the “Out of Stock” status for a product. This can be frustrating if you have a product that goes in and out of stock frequently, or if you accidentally mark a product as out of stock and need to change it back. Fortunately, there is a way to change the out of stock status for a product in WooCommerce, though it requires editing some code.

To change the out of stock status for a product in WooCommerce, you will need to access your site’s code via FTP or through your hosting control panel. Once you have access to your site’s files, open the wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php file in a text editor. Around line 1240, you will see the following code:

$stock = get_post_meta( $thepostid, '_stock', true );
echo '<span class="stock_status" id="_stock_status">' 
. wc_get_stock_html( $product ) . '</span>';

Replace this code with the following:

PRO TIP: If you are thinking about changing the out of stock status in WooCommerce, be aware that this can have unintended consequences. For example, if you change the stock status of a popular product to “out of stock,” this can cause people to panic and buy up all the remaining inventory. This could lead to shortages and unhappy customers.
$stock = get_post_meta( $thepostid, '_stock', true );
$backorders = get_option( 'woocommerce_allow_backorders' );
$manage_stock = (
     'yes' === get_option(
     'woocommerce_manage_stock' ) ) ? true : false;
?>
<div class="control">
<label for=" stock_status" class="label"><?php _e(
     'Stock status', 'woocommerce' ); ?>
<?php echo wc_help_tip( __(
     'Controls whether or not the product is marked as "in stock"
or "out of stock" on the frontend.',
     'woocommerce' ) );
     // @codingStandardsIgnoreLine ?></label>
<select name=" _stock_status" id=" _stock_status"
class="select short wc-enhanced-select dropdown visibility"
     data-allowclear="true"
     data-placeholder=""
     tabindex=""
     aria-hidden="true" 
     style="">;
<?php foreach (
   wc_get_product_stock_status_options() as $key = > $value ) : ?>;
<option value=" <"?php echo esc_attr( $key ); ?>"
<"?php selected( $key === $_stock['value'] ); ?>" >"
Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.