I want to hide price and totals from cart/checkout Summary. You can see in below image.
How can I achieve this functionality with a custom module? Is there any common file from I can hide the price?
Thanks.
I want to hide price and totals from cart/checkout Summary. You can see in below image.
How can I achieve this functionality with a custom module? Is there any common file from I can hide the price?
Thanks.
You can try below layout XML to remove such JS components.
Assume your custom module name is "Company_MyModule".
step 1) To Remove elements from Cart Page
create checkout_cart_index.xml
under
/app/code/Company/MyModule/view/frontend/layout
File : checkout_cart_index.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="checkout_cart_item_renderers"/>
<body>
<referenceBlock name="checkout.cart.shipping">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="block-summary" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
<referenceBlock name="checkout.cart.totals">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="block-totals" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
step 3) To Remove elemnt from Checkout Page
create checkout_index_index.xml
under
/app/code/Company/MyModule/view/frontend/layout
File : checkout_index_index.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<item name="summary" xsi:type="array">
<item name="children" xsi:type="array">
<item name="totals" xsi:type="array">
<item name="children" xsi:type="array">
<item name="subtotal" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
<item name="shipping" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
<item name="grand-total" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</referenceContainer>
</body>
</page>
step 2) Remove static content and cache
sudo rm -rf var/view_preprocessed/*
sudo rm -rf var/pub/static/*
sudo rm -rf var/cache/*
sudo rm -rf var/generated
sudo rm -rf var/composer_home
sudo rm -rf var/page_cache
sudo rm -rf var/view_preprocessed
sudo rm -rf pub/static/frontend/*
You can check this link for more information.
Overriding the js file called "price-utils.js" from
**Vendor\Magento\module-catalog\view\base\web\js\price-utils.js**
into the module with "requirejsconfig.js" in our module as below:
var config = { map: { '*': { 'Magento_Catalog/js/price-utils': 'Name_Module/js/price-utils' } } };
then copy the file into your module
@ app\code\Name\Module\view\frontend\web\js\price-utils.jsnow change return value in "function formatPrice" it is return formated price.
That's it. one thing I point here for everyone it will hide the price from cart totals, checkout totals, summery and from product option's price as well.
As I required to hide price from front end it is a good solution for me.
Hope it will help others.
Happy Coding.....
To Hide prices blocks only, use below XML to hide "subtotal","grand-total","tax","Shipping" components.
File: checkout_cart_index.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="checkout_cart_item_renderers"/>
<body>
<referenceBlock name="checkout.cart.totals">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="block-totals" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Disable subtotal-->
<item name="subtotal" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
<!-- Disable shipping-->
<item name="shipping" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
<item name="tax" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
<!-- Disable grand-total-->
<item name="grand-total" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>