0

I want to hide Price from recently viewed products for certain products only(Based on its attribute value).How can I do that? Please anyone help me to do that. Thank you in advance.

1
  • I have added answer. Please check and approve my answer.
    – ZealousWeb
    Feb 12, 2021 at 6:34

1 Answer 1

1

You can achieve this by below piece of code. Here i have load product using product repository in phtml file , but you can load it anywhere (In helper, block file)

Here i have attribute code name "new" so i am applying condition for show/hide price on the basis of "new"(boolean) attribute value.

First , please override vendor/magento/module-catalog/view/frontend/templates/product/list/items.phtml file in your theme (app/design/frontend/packangename/theme/Magento_Catalog/view/templates/product/list/items.phtml).

Copy and paste all code from core file in theme overridden file. Find function getProductPrice($_item) in file and set below code according to your attribute value

<?php 
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
    $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
    $product = $productRepository->getById($_item->getId());
?>
<?php if($product->getNew()): ?>
    <?= /* @noEscape */ $block->getProductPrice($_item) ?>
<?php endif; ?>

This way you can show/hide price for certain products only(Based on its attribute value).

Please check and let me know if you have any query.

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.