Magento 1 How to Hide Empty or Null Attribute in Compare Page

The question:

I’ve realised there are many answer which actually are technically incorrect because they only are taking into account one product. They remove any attribute that is empty or null even if the second product’s attribute is not null or empty.

So I decided to post an answer.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

We need to override the block class Mage_Catalog_Block_Product_Compare_List and function getAttributes(), this way we have pre sorted array list of attributes instead of having to do the changes at template level.

public function getAttributes()
  if (is_null($this->_attributes)) {
     $this->_attributes = $this->getItems()->getComparableAttributes();

  // Remove Null Attribute From Compare List
  foreach($this->_attributes as $attribute) {
     $size  = sizeof($this->getItems());
     $count = 0;

     foreach($this->getItems() as $item) {
        $itemAttribute = $item->getData($attribute->getName());
        $trimAttribute = trim($itemAttribute);
        if(is_null($itemAttribute) || empty($trimAttribute)) {

        if($count == $size) {

  return $this->_attributes;


All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment