In Magento 1, there is custom message based on product id, added in cart as below:-

enter image description here

Same I want to show in Magento 2.3.

For static message I follow this article.

Please help me how to add condition based on product ids in checkout .


Try the following way:


<?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">
        <referenceBlock name="checkout.root">
                <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">SR_MagentoCommunity/js/view/custom-block</item>


], function ($, ko, Component, quote) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'SR_MagentoCommunity/custom-block'
        isVisibleFirstBlock:  ko.observable(false),
        isVisibleSecondBlock: ko.observable(false),
        initialize: function () {
            var items = quote.getItems();
            var hasProductInCart = 0;
            $.each(items, function(index, item) {
                if (item.product_id == 14) {
                    hasProductInCart = 1;

            var regionId = 0;
            var self = this;
            quote.shippingAddress.subscribe(function (address) {
                regionId = address.regionId;
                if (hasProductInCart && (regionId == 12)) {
                } else {

            return this;


<!-- ko if: (isVisibleFirstBlock()) -->
        <span data-bind="i18n: 'Custom Message 1'"></span>
<!-- /ko -->

<!-- ko if: (isVisibleSecondBlock()) -->
        <span data-bind="i18n: 'Custom Message 2'"></span>
<!-- /ko -->
  • I also want to check region id with product id, how to get region id here. Thanks – Purushotam Sharma Apr 4 at 2:35
  • 1
    Check updated answer – Sohel Rana Apr 4 at 13:01
  • Accept this answer, that will help other – Sohel Rana Apr 4 at 16:01
  • Already upvote for your answer – Purushotam Sharma Apr 4 at 16:13

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.