I created a custom module which adds an input in shipping method for all products in the checkout page. I want to hide and show this input as per specific category products and replaced this old to new inputs on the checkout page. Does anyone knows this? Thanks in advanced.


<item name="shippingAdditional" xsi:type="array">
 <item name="component" xsi:type="string">uiComponent</item>
  <item name="displayArea" xsi:type="string">shippingAdditional</item>
     <item name="children" xsi:type="array">
        <item name="delivery_date" xsi:type="array">
           <item name="component" xsi:type="string">Module_name/js/view/delivery-date-block</item>


If your extension has a block to render the phtml (I hope it does) you could create a plugin and set a method as follows:

public function afterToHtml($subject, $result) { if (condition to show is true) { return $result; } else { return ""; } }

You can see how to create a plugin in http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html


To handle this in the javascript you are going to need to do a few steps:

  • Create a configuration for setting which categories you want to hide/show.
  • Create a config provider an set your business logic there
  • Load the data from your custom config provider at Module_name/js/view/delivery-date-block and set if the template should be visible or not.
  • At your template you could use a if binding http://knockoutjs.com/documentation/if-binding.html
  • @ Thiago Thanks for reply.. Actually I am showing custom input defining in checkout_index_index layout file and setting html template using knockout js file. Can you give me more details on which class I extends with "after" in plugin or how can I hide custom block. sorry for trouble, i am beginner in magento. – Rahul Feb 18 '18 at 18:45
  • Could you update the description and paste the checkout_index_index.xml, please? – Thiago Lima Feb 18 '18 at 21:01
  • I updated the description kindly check it and let me know. – Rahul Feb 19 '18 at 5:14
  • @Rahul here you go – Thiago Lima Feb 19 '18 at 9:38
  • Thanks @Thiago, Its work for me. refer this Link to hide and show template as per config. – Rahul Feb 21 '18 at 19:00

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.