1

sorry my english is not good.

i have this function action code from this page: Display always stock status without quantity in WooCommerce and i want not-show stock quantity when Not-entered

//* Add stock status to archive pages
function envy_stock_catalog() {
global $product;
if ( $product->is_in_stock() ) {
    echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>';
} else {
    echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>';
}
}
 add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );
ramin
  • 11
  • 2
  • Could you explain what you are trying to achieve. There are a couple of questions left unanswered here. You can disable show stock, in woocommerce settings > stock management. Here you can enable it, enable it to show, stock amount, without amount or only when stock is low. "I want disabled show stock quantity when non-entered or unknown stock quantity." This confuses me.. when will stock be unknown? There will only be stock management on products where it is enabled, and you will have to enter amount after that, so it can never be unknown. It can just be in stock, managed or disabled/ N/A. – Pandusen Aug 19 '21 at 13:10
  • There are three models: 1. enter a number. 2.It is zero 3. do not enter any numbers. i want no show stock quantity when do not entered any numbers. Because I used ::before in CSS. – ramin Aug 20 '21 at 12:45

1 Answers1

0

Could you explain more? As per our understanding, you want to show the only in-stock product.

How to Hide Out of Stock Products:

a) Open WordPress dashboard and Go to WooCommerce -> Settings.

b) Click on the Products Tab > Inventory sub-tab

c) Check the option Out Of Stock Visibility that hides the out of stock products

enter image description here

Rajeev Singh
  • 1,724
  • 1
  • 6
  • 23
  • There are three models: 1. enter a number. 2.It is zero 3. do not enter any numbers. i want no show stock quantity when do not entered any numbers. Because I used ::before in CSS. – ramin Aug 20 '21 at 12:46