1

I have created one module which has admin side configuration to enable/disable the module. Now I want to hide the prices from "orders, customer account, and order view ". Means I want to hide the price, so the user can not see the price other information should be there.

How could I hide the price and totals from "cart/order/email" if the module is enabled?

I have one helper function which returns the value of the configuration.

I found the way to hide price from "order view, invoice, shipment, etc", I created one plugin:

<type name="Magento\Sales\Model\Order">
    <plugin name="price_hide_from_orders" type="Name\Module\Plugin\Order\Pricehide" sortOrder="1" disabled="false"/>        
</type>
namespace Name\Module\Plugin\Order;

class Pricehide
{
    protected $helperData;

    public function __construct(
        \Name\Module\Helper\Data $helperData
    ) {
        $this->helperData = $helperData;
    }
    function afterFormatPrice($price, $addBrackets = false)
    {
        if($this->helperData->getModuleStatus()): // check moude enable or not
             return $this->helperData->getPriceMessage(); // message instead of price
        else:
            return $this->formatPricePrecision($price, 2, $addBrackets);
        endif;
    }
}

It gives error as below:

Fatal error: Uncaught Error: Call to undefined method Name\Module\Plugin\Order\Pricehide::formatPricePrecision() in app\code\Name\Module\Plugin\Order\Pricehide.php:18 Stack trace: #0 

In "Magento\Sales\Model\Order.php" there are dependent functions available in Order.php file, how can we use it?

Thanks.

  • Use plugin for - Magento\Catalog\Pricing\Render\FinalPriceBox – Aditya Shah Dec 25 '18 at 8:03
  • 1
    Please check my answer magento.stackexchange.com/questions/253249/… – Dhairya Shah Dec 25 '18 at 13:15
  • will this hide the price and totals from "cart/order/email"? – Utsav Gupta Dec 26 '18 at 5:58
  • using "FinalPriceBox" plugin it is hiding price from "category page, compare products, product view page" but not from order view, cart and checkout page. – Utsav Gupta Dec 26 '18 at 7:11

Your Answer

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

Browse other questions tagged or ask your own question.