1

I remove price from product view page using below line of code

  <referenceBlock name="product.info.price" remove="true" />

This is working perfectly.but i need to show price in only simple product on product view page and did not show in configurable,bundle,grouped,virtual product.

can someone help to achieve this solution?

2 Answers 2

3

Override the below file

catalog_product_view_type_simple.xml

<referenceBlock name="product.info.price" remove="false" />

Use the above code to show the price only in the simple product on product view page

0

Using Preference:-

app/code/Vendor/Module/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\Module\Pricing\Render\FinalPriceBox" />
</config>

app/code/Vendor/Module/Pricing/Render/FinalPriceBox.php

<?php

namespace Vendor\Module\Pricing\Render;


use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\View\Element\Template\Context;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
    protected $registry;

    protected $helperData;

    public function __construct(Context $context, SaleableInterface $saleableItem, PriceInterface $price, RendererPool $rendererPool, array $data = [], SalableResolverInterface $salableResolver = null, MinimalPriceCalculatorInterface $minimalPriceCalculator = null,\Magento\Framework\Registry $registry,\Shineretrofits\CallForPrice\Helper\Data $helperData)
    {
        $this->registry = $registry;
        $this->helperData = $helperData;
        parent::__construct($context, $saleableItem, $price, $rendererPool, $data, $salableResolver, $minimalPriceCalculator);
    }

    protected function wrapResult($html)
    {
        $current_product = $this->registry->registry('current_product');

        if($current_product->getTypeId() == 'simple')
        {
                $result = parent::wrapResult($html);
        }else{
            $result = '';
        }

        return $result;
    }

}

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.