I want to display a li on product-page, if the product got upsell products.

What is the condition that I need to check for this?


2 Answers 2


You can try this.

<?php $_product = $this->getProduct(); ?>

<?php if (count($_product->getUpSellProductIds()) > 0) : ?>

    <!-- your list should come inside this condition-->

<?php endif; ?>

If you have a valid product object on $_product, then getUpSellProductIds() will provides you an array of upsell product ids related to the product which holds by $_product. So what we are doing here is checking whether the array count is greater than zero. If it is yes, then shows the list.

Hope you get the concept.

  • Happy to help you :) Commented Jan 27, 2015 at 7:15
  • I wish to get only the in stock upsell product collection, then how do i add filter while getting a collection itself
    – Jaisa
    Commented Jun 13, 2018 at 3:53

This is simple. In your view.phtml file write this code where your want to display "li" or any HTML code:

enter image description here

Also you can use $upsell_products in a foreach() loop to get each product and attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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