0

I just want to show the message on the checkout page, when COD is not applicable. for Eg: if we are adding the minimum order total 500 for COD.

Then any user tries to purchase below 500 then they able to see a message on checkout page. Like: COD not available to on cart value below 500.

Please help me to create this.

3
  • exactly where you want this message in checkout page?
    – Hiren
    Commented Feb 7, 2020 at 12:55
  • perhaps it would be better to remove the COD payment method if order total below 500.
    – paj
    Commented Feb 7, 2020 at 22:03
  • On Checkout page where all payment method show excluding COD. Commented Feb 10, 2020 at 9:45

1 Answer 1

0

You can display your custom message on checkout page using following ways, do some customization in code as per your need

app/code/Vendor/Module/view/frontend/layout/checkout_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <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="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="billing-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="beforeMethods" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="custom_block" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Vendor_Module/js/view/custom-block</item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

app/code/Vendor/Module/view/frontend/web/js/view/custom-block.js

define(['jquery', 'ko', 'uiComponent', 'Magento_Checkout/js/model/totals'], function ($, ko, Component, totals) 
{
    'use strict';

    return Component.extend(
    {
        defaults: { template: 'Vendor_Module/custom-block' },
        isDisplayMessage: ko.observable(false),

        initialize: function ()
        {
            this._super();
            var self = this;

            if(totals.getSegment('grand_total').value < 500)
            {
                self.isDisplayMessage(true);                
            }

            return this;
        }
    });
});

app/code/Vendor/Module/view/frontend/web/template/custom-block.html

<!-- ko if: (isDisplayMessage()) -->
    <div>
        <span data-bind="i18n: 'COD not available to on cart value below 500'"></span>
    </div>
<!-- /ko -->

You can see in this image.

enter image description here

2
  • Thanks for your reply. I have added the same code but it's not working. one more things that we need to check COD Available or not then show the message. Ref: prntscr.com/r03tbd Commented Feb 10, 2020 at 10:16
  • clean cache remove pub/static var/view_preprocessed and try again
    – Hiren
    Commented Feb 11, 2020 at 10:17

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.