0

First I try to modify the code directly of core file.

vendor\magento\module-offline-payments\view\frontend\templates\form\cashondelivery.phtml

I added testing code like this.

<?php $instructions = $block->getInstructions(); ?>
<?php if ($instructions): ?>
    <?php echo "MY CUSTOM CODE HERE"; ?>
    <?php $methodCode = $block->escapeHtml($block->getMethodCode());?>
    <div class="items <?= /* @noEscape */ $methodCode ?> instructions agreement" id="payment_form_<?= /* @noEscape */ $methodCode ?>" style="display: none;">
        <?= /* @noEscape */ nl2br($block->escapeHtml($instructions)) ?>
    </div>
<?php endif; ?>

Here I have one question.

Where my custom message show? Currently it not showing my message any where on checkout???

Thanks in advance.

3

You have to work on vendor/magento/module-offline-payments/view/frontend/web/template/payment/cashondelivery.html

As magento2 manage checkout steps manage from knockout js & UI element. So you have to copy cashondelivery.html to

app/design/frontend/{ThemeVendor}/{Themename}/web/template/payment/cashondelivery.html

and Do add this text to here.

Then do static content deploy and cache flush.

By Custom module

Create requirejs-config.js at /app/code/{VenDorName}/{Module}/view/frontend. Override the knockout js using and it code

requirejs-config.js code is below

var config = {
    map: {
        '*': {
            'Magento_OfflinePayments/js/view/payment/method-renderer/cashondelivery-method' : '{VenDorName}_{Module}/js/view/payment/method-renderer/cashondelivery-method',
        }
    }
};

Create knock view file cashondelivery-method.js at /app/code/{VenDorName}/{Module}/view/frontend/web/js/view/payment/method-renderer/.

and code is

define([
    'Magento_Checkout/js/view/payment/default'
], function (Component) {
    'use strict';

    return Component.extend({
        defaults: {
            template: '{VenDorName}_{Module}/payment/cashondelivery'
        },

        /**
         * Returns payment method instructions.
         *
         * @return {*}
         */
        getInstructions: function () {
            return window.checkoutConfig.payment.instructions[this.item.method];
        }
    });
});

And copy vendor/magento/module-offline-payments/view/frontend/web/template/payment/cashondelivery.html to

/app/code/{VenDorName}/{Module}/view/frontend/web/template/payment/cashondelivery.html

After that you have to do Static content deploy

  • I want to overide file into custom extension not theme, what to do? – Dhiren Vasoya Oct 2 '18 at 9:22
1

module-offline-payments\view\frontend\templates\form\cashondelivery.phtml is for Check Out with Multiple Addresses

  • ok let me check and is that any same file for single address check out? – Dhiren Vasoya Oct 2 '18 at 8:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.