0

I want to hide price and totals from cart/checkout Summary. You can see in below image.

enter image description here

How can I achieve this functionality with a custom module? Is there any common file from I can hide the price?

Thanks.

4
  • 1
    Hi Utsav, you can see the html files on this location: vendor/magento/module-checkout/view/frontend/web/template/cart/totals
    – Rajan Soni
    Commented Dec 28, 2018 at 6:07
  • yes, I can see that, but i need the common file/function which called each time when total, subtotal, grand total called. Commented Dec 28, 2018 at 7:32
  • There is no such file where you can hide the price and it will affect for all areas. You need to edit every files which uses prices to display for different areas. Commented Dec 28, 2018 at 7:40
  • Thanks all. but let you know which files need to be change? Commented Dec 28, 2018 at 7:44

3 Answers 3

2

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.

enter image description here

enter image description here

2
  • Appreciated your answer. That is correct. but I don't want to hide the whole block. just need to hide the prices. Thanks Commented Dec 28, 2018 at 12:38
  • You can check my 2nd answer to hide specific component only. Thanks Commented Dec 28, 2018 at 12:52
0

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.js
now 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.....

0

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>

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.