How to get last added product in collection?

Hello

I developed a one custom app for show deals of the day. In this app we can add deal on any product. So when someone create a deal and choose product then I’m adding that product in one specific collection “Daily Deals”. So now Daily deals section in any page I needs to show last added product in that collection. So is there any way we can last added product in collection?

Right now when we do sort : published_at then it return last create product but I need last added product in that Daily Deals collection.

I’m pretty sure there is not really any way of achieving that data. Not via the liquid objects nor the API response data.

However, this might be possible to hack, by selecting “Manual” sort on the collection. Like this, I believe products are added to the bottom of the collection always. Now you can simply achieve it by getting the last product.

Not entirely sure though, so you would have to test it yourself.

{%- assign last_product = collection.products | last -%}