I'm having trouble displaying the out of stock size without text "Out of Stock".

Example: Select Size

And here is how its showing up in DOM:

<span class="option out-of-stock" value="370">25 (Out of Stock)</span>

Also here is the jQuery piece that adds class to this span:

jQuery(".ui-segment span.option:contains('(Out of Stock)')").addClass('out-of-stock');

Is there a way to strip out the text "(Out of Stock)"?

or can I somehow generate only Size number eg:

"25" without text "Out of Stock"? So that instead of 25 Out of Stock it displays as 25

  1. You have a config in admin to don't display the Out of stock products System>configuration>catalog>inventory>Display out of stock products>NO

  2. If you want to hide the sizes that contains out of stock, you can do it like this:


<span><p>26 out of stock</p></span>
<span><p>28 out of stock</p></span>


$.expr[":"].containsNoCase = function(el, i, m) {
    var search = m[3];
    if (!search) return false;
    var pattern = new RegExp(search,"i");
    return pattern.test($(el).text());
$(document).ready(function() {
    $("span p:containsNoCase('out of stock')").parent('span').hide();


  • I have tried System>configuration>catalog>inventory>Display out of stock products>NO but this doesnt remove "Out of Stock" text. As per js approach it removes the size numbers as well, which I need to preserve. – lvekua Sep 27 '17 at 14:27
  • No, look my jsfiddle demo, if the span contain the 'out of stock' sting, he hide it, you have to customise the js according your div, span, id etc... – PЯINCƏ Sep 27 '17 at 15:00
  • I'm sure your answer makes sense, but unfortunately I'm not very literate in js, jQuery and I'm unable to remove only "Out of Stock" and keep the existing numbers (( e.g 25, 26, 27, 28 it removes the entire span and leaves me with 25, 27 – lvekua Sep 27 '17 at 15:19
  • Look your question : can I somehow generate only Size number for out of stock products ! your question is rather blurred – PЯINCƏ Sep 27 '17 at 17:50
  • I have edited question, hope it makes more sense. – lvekua Sep 27 '17 at 18:26

You can remove out of stock text from file


in this file look for code something like $_option->label and with this code if there is any static text added for (Out of Stock) , you can simply comment or remove that text.

  • thanks for the answer but I don't have these files neither in basse, default or my_package. – lvekua Sep 27 '17 at 14:22
  • Are you using any extension for attribute swatches? – Piyush Sep 27 '17 at 18:12
  • I'm sure there is a customization from previous developer. I just cannot find that piece of code which generates that string. I used commerce bug, template hints, etc. cant seem to find it. – lvekua Sep 27 '17 at 18:22

This is what worked for me:

jQuery(".ui-segment span.out-of-stock").text(function(index, text) {
    return text.replace(' (Out of Stock)', '');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.