0

enter image description here

We have scenario with GDex and Yamato shipping partner and our shipping cost will be changing at run-time so we don't want to allow to select shipping methods(HIDE) to customer but want to apply shipping method programmatically based on our condition. This things, we need to implement in magento 2. Thanks In advance

  • If you have only one shipping method you can hide shipping section from checkout page using css. – John Jun 29 '17 at 6:13
  • I am having multiple shipping methods – Pramod Kharade Jun 29 '17 at 6:14
0

If you are not select shipping method then you are not able to place the order. Any way to achieve your task you need to follow this step:

Vendor: Vendor

ModuleName: CheckoutStep

1) Override checkout_index_index.xml in your module and define your own component in shipping step

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


<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" 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="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="shippingAddress" xsi:type="array">
                                                    <item name="component" xsi:type="string">Vendor_CheckoutStep/js/view/krish-shipping</item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

2) Create krish-shipping.js and define your own shipping template

app/code/Vendor/CheckoutStep/js/view/krish-shipping.js

define(
    [
        'jquery',
        'ko',
        'Magento_Checkout/js/view/shipping'
    ],
    function(
        $,
        ko,
        Component
    ) {
        'use strict';
        return Component.extend({
            defaults: {
                template: 'Vendor_CheckoutStep/shipping'
            },

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

        });
    }
); 

3) Copy shipping.html

From

vendor/magento/module-checkout/view/frontend/web/template/shipping.html

To

app/code/Vendor/CheckoutStep/view/frontend/web/template/shipping.html

3) Remove html after class checkout-shipping-method and add Your message

<!--Shipping method template-->
<li id="opc-shipping_method"
    class="checkout-shipping-method"
    data-bind="fadeVisible: visible(), blockLoader: isLoading"
    role="presentation">
    <div class="checkout-shipping-method">
    <div class="step-title" data-bind="i18n: 'Shipping Methods'" data-role="title"></div>
        <div data-bind="i18n: 'Your Custom Message'" data-role="title"></div>
    </div>
</li>

for reference you can check this link out

  • "If you are not select shipping method then you are not able to place the order:" can we apply shipping method at background and how we can place order without selecting shipping methods? @Riddhish Bhayani – Pramod Kharade Jun 29 '17 at 7:19
  • @PramodKharade Yes you have to set fee shipping in the background. As magento don’t allow to place order without shipping method. – Riddhish Bhayani Jun 29 '17 at 8:38
  • where from we can set shipping methods without showing to customer ?(File path) – Pramod Kharade Jun 29 '17 at 8:42
  • @ Riddhish Bhayani , I am having Gdex and Yamato shipping methods but I want to make it available only one shipping methods based on order sequencing logic so shipping cost will be changing based on sequence at run time . Could you please suggest me right solution ? – Pramod Kharade Jul 4 '17 at 3:47

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.