What can we help you with?

How to Display Stock Status in the Product Page Without Enabling the Manage Stock Option?

The following code snippet will help you display the stock status on the product page even if you hide the price or cart button using the ELEX catalog mode and role-based pricing plugin.

Generally, WooCommerce will not show the stock status unless you enable the ‘Manage stock’ option at the product level and define the stock quantity.

But don’t worry, once you use the code snippet, our plugin will show the product stock status without enabling the ‘Manage stock’ option as you just need to define the code snippet in the activated theme file.

Here is the code.

/**
 * Show stock information on individual product pages
 */
add_filter('woocommerce_short_description','elex_add_text_short_descr');
function elex_add_text_short_descr($description){
	global $product;
	$stock_status_html = '';
	$stock_status = $product->get_stock_status();
	if(!is_shop()){
		// available
		if ( $stock_status == 'instock' ) {
			$status= ' In stock';
			$stock_status_html= 'style="color:green;" font-size: 17px; ">'.$status.'';
		
		}
		// out of stock
		if ($stock_status == 'outofstock') {
			$status = ' Out of stock';
			$stock_status_html = 'style="color:red; font-size: 17px;">'.$status.'';
		}
		//backorder
		if ($stock_status == 'onbackorder') {
			$status = ' On backorder';
			$stock_status_html = 'style="color:orange; font-size: 17px;">'.$status.'';
		}
		return $description . $stock_status_html;
	}
	
    
}

You can simply add the above code in the activated theme’s functions.php file on your site and save the changes for implementing the code. Check the below screenshot to understand this better:Display Stock Status in the Product Page

Product page before implementing the code snippet:

Product page before implementing the code snippet:

Product Page after implementing the code snippet:

Display stock status in product page

To know more about the product, check out the ELEX WooCommerce Catalog Mode, Wholesale & Role Based Pricing

Or check out the documentation section for more related articles.

For more creative snippets of information visit elex-snippets.

Previous How To Override The Role-based Price When The Sale Price Is Lower?
Next How to offer WooCommerce Category Discount?
You must be logged in to post a comment.