Paste the following code in the active theme’s functions.php:
/* if the product quantity is between X and X, display "plus que X en stock" in cart and checkout */
add_filter( 'woocommerce_cart_item_name', 'showing_stock_in_cart_items', 99, 3 );
function showing_stock_in_cart_items( $item_name, $cart_item, $cart_item_key ) {
// The WC_Product object
$product = $cart_item['data'];
if (empty($product)) {
return $item_name;
}
// Get the stock
$stock = $product->get_stock_quantity();
// When stock doesn't exist
if (empty($stock)) {
return $item_name;
}
// display the stock
if ($stock >= '1' && $stock <= '3') { /* was ($stock <= '3') */
$item_name .=" × " . $cart_item['quantity'] . "" . '
'.__( "Plus que " .$stock. " en stock","woocommerce").'
';
} else {
$item_name .=" × " . $cart_item['quantity'] . "";
}
return $item_name;
}
Edit quantity (range) and text as needed.
Then, paste the following code in Appearance > Customize > Additional CSS:
/* remove native item quantity in checkout */
.woocommerce-checkout #order_review .product-quantity {
display: none;
}
/* remove stock function quantity in cart and mini-cart*/
.woocommerce-cart .cart_item .function-product-quantity,
.woocommerce-mini-cart .function-product-quantity {
display: none !important;
}
Source: https://stackoverflow.com/questions/59001052/woocommerce-show-stock-status-on-cart-page (+ additional edits made by myself)