Jump to content

How to change "Last items in stock!" to "Only, X left in stock!" on product page? (Solved)


MrWade

Recommended Posts

Yes, I am using PS v 8.1.7

How can I change the "Last items in stock!" to "Only, X left in stock!" on the product page?

I have the stock settings as Display remaining quantities when the quantity is lower than 5.

Is there a code I need to change?

Thank You!
Wade

Edited by MrWade
Solved (see edit history)
Link to comment
Share on other sites

In template catalog/_partials/product-details.tpl change

  {block name='product_quantities'}
    {if $product.show_quantities}
      <div class="product-quantities">
        <label class="label">{l s='In stock' d='Shop.Theme.Catalog'}</label>
        <span data-stock="{$product.quantity}" data-allow-oosp="{$product.allow_oosp}">{$product.quantity} {$product.quantity_label}</span>
      </div>
    {/if}
  {/block}

with

  {block name='product_quantities'}
    {if $product.show_quantities}
      <div class="product-quantities">
        <span data-stock="{$product.quantity}" data-allow-oosp="{$product.allow_oosp}">{l s='Only, %stockvalue% left in stock!' d='Shop.Theme.Catalog' sprintf=['%stockvalue%' => $product.quantity]}</span>
      </div>
    {/if}
  {/block}

 

Link to comment
Share on other sites

On 1/9/2025 at 10:53 AM, MrWade said:

Yes, I am using PS v 8.1.7

How can I change the "Last items in stock!" to "Only, X left in stock!" on the product page?

I have the stock settings as Display remaining quantities when the quantity is lower than 5.

Is there a code I need to change?

Thank You!
Wade

Hi Wade,

To change "Last items in stock!" to "Only X left in stock!", go to International > Translations in the PrestaShop back office, edit Themes Translations, and replace the text in the relevant string. Save your changes and clear the cache. Let me know if you need more help!

Link to comment
Share on other sites

Hi Wade,

To change "Last items in stock!" to "Only X left in stock!" in PrestaShop v8.1.7:

Go to International > Translations in your admin panel.

Select Front Office Translations, and your language.

Search for "Last items in stock!" and change it to "Only X left in stock!".

Save the changes.

This should update the message on your product pages. Let me know if you need further help!

Link to comment
Share on other sites

What does the product (category) do with the stock counts? What I am wanting to do is to show Only, 3(X) left in stock! When I have stock less than 5 its shows "Last items in Stock".

Link to comment
Share on other sites

You may try to delete your browser history to get ride of the old page and make it load it fresh from your webshop server.

 

When I try to find something in the PS files I download the shop to my local drive and use notepad++ to search through the files for a specific text. Then you see in which file it is and can change it there with notepad++ and upload it back to the server or change it live at the server.

Link to comment
Share on other sites

Hello,

The translation system isn't randomly injecting variables into the texts, this is why you will always see X. The above comments about translations seem to be generated with AI and you should ignore them.

You will need to edit the following file: src/Adapter/Presenter/Product/ProductLazyArray.php

On ~ lines 981 - 985, you should see the following:

$this->product['availability_message'] = $this->translator->trans(
    'Last items in stock',
    [],
    'Shop.Theme.Catalog'
);

You need to replace it with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d left in stock!',
    ['%d' => $availableQuantity === 0 ? 0 : $availableQuantity + 1],
    'Shop.Theme.Catalog'
);

Now, in my case the quantity seems to always be less by one for some reason, this is why I added + 1 in there. If, after making the above changes you see an incorrect number, you can change the above code with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d left in stock!',
    ['%d' => $availableQuantity],
    'Shop.Theme.Catalog'
);

Once the changes are saved, you should be able to see the changes, as shown in my screenshot.

 

Screenshot 2025-01-12 095357.png

Edited by Andrei H (see edit history)
  • Thanks 2
Link to comment
Share on other sites

  • MrWade changed the title to How to change "Last items in stock!" to "Only, X left in stock!" on product page? (Solved)
  • 3 months later...

Ok, I am back again. I had to pre-launch the store. There is no "In Stock" under the Add to Cart in the product page. I am using the latest PS Version 8.2?

Link to comment
Share on other sites

Posted (edited)

To change the default "Last items in stock!" message to display something like "Only X left in stock!" on the product page, you must modify the relevant template file in your e-commerce platform, such as PrestaShop. Typically, this message is generated in a template file like product.tpl or a stock-related module file. You will locate the line that outputs "Last items in stock!"—often associated with a stock quantity condition—and replace or adjust it to dynamically include the actual stock count. For example, you could use a variable like {$product.quantity} and edit the text to say: "Only {$product.quantity} left in stock!" After making the changes, clear the cache from your admin panel or manually from the /cache folder so that the new message displays correctly on the frontend. This approach gives your customers a clearer sense of urgency and can help drive conversions. ucharts

Edited by john533 (see edit history)
Link to comment
Share on other sites

4 hours ago, john533 said:

To change the default "Last items in stock!" message to display something like "Only X left in stock!" on the product page, you must modify the relevant template file in your e-commerce platform, such as PrestaShop. Typically, this message is generated in a template file like product.tpl or a stock-related module file. You will locate the line that outputs "Last items in stock!"—often associated with a stock quantity condition—and replace or adjust it to dynamically include the actual stock count. For example, you could use a variable like {$product.quantity} and edit the text to say: "Only {$product.quantity} left in stock!" After making the changes, clear the cache from your admin panel or manually from the /cache folder so that the new message displays correctly on the frontend. This approach gives your customers a clearer sense of urgency and can help drive conversions.

Ok, I understand that. When I have over let say 100 items in stock. There is no "In Stock" under the add to cart button.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...