2

I need to hide price in selected product in category list page. [PFA]

enter image description here

I know, there are many extensions for it.

I have used 2-3 extensions for the same but it changes my theme. Because they override list.phtml file.

I need to change only Price div and add my custom code but I can't figure out how to achieve this?

Edit

Before Extension

enter image description here

After Extension

enter image description here

Does anyone know block name for that Price div ?

  • Are you want to hide price only from list page? – Rakesh Jesadiya Jun 22 '17 at 5:20
  • I have dropdown in product edit page in admin side. So price should be hide in which I have select yes and need to put a button instead of Add to cart button. – Jigar Dhaduk Jun 22 '17 at 5:38
  • have you overrider list.phtml file in your theme? – Rakesh Jesadiya Jun 22 '17 at 5:43
  • Yes. And so when I use any other theme, it doesn't look good because of my list.phtml file. – Jigar Dhaduk Jun 22 '17 at 5:50
1
+50

You can set your condition based on your product value show/hide in list file,

Your theme list.phtml file would be, app/design/frontend/{Packagename}/{themename}/Magento_Catalog/templates/product/list.phtml file

Price rendering in list file using one line, <?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?>

Inside list.phtml file

<?php 
    $productShow = Your condition.....;
?>
<?php if($productShow){ ?>
<?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?>
<?php } ?>

Now Block file,

function for price render is coming from block file,

Module-catalog/Block/Product/AbstractProduct.php

 public function getProductDetailsHtml(\Magento\Catalog\Model\Product $product)
    {
        $renderer = $this->getDetailsRenderer($product->getTypeId());
        if ($renderer) {
            $renderer->setProduct($product);
            return $renderer->toHtml();
        }
        return '';
    }
  • Would you please explain with more words ? I haven't more knowledge of where to create file and where to write that function getProductDetailsHtml. – Jigar Dhaduk Jun 22 '17 at 7:13
  • This is default core function of magento you have to write your code inside list.phtml file of your theme. – Rakesh Jesadiya Jun 22 '17 at 7:17
  • I am creating extension and list.phtml file in it. I can't change in other vendor's theme folders. At this point, design issue is occurs. One can change theme after some time, then again I have to change theme's list.phtml file. – Jigar Dhaduk Jun 22 '17 at 7:24
  • you can keep above code in list.phtml of your module – Rakesh Jesadiya Jun 22 '17 at 7:27
  • That code is only for price, right ? Do I need to keep other code as it is ? – Jigar Dhaduk Jun 22 '17 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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