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

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 1
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)

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...