magento2,blocks,overrides – How to Override Block .php File in Magento 2

blocksmagento2overrides

I got this file:

module-sales/Block/Adminhtml/Order/Create/Shipping/Method/Form.php

I want to override this in a custom module.

How can I do that?
Thanks!

Best Answer

For Block use the below code in your module's di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\Form" type="[VendorName]\[ModuleName]\Block\Adminhtml\Order\Create\Shipping\Method\Form"/>
</config>

For phtml override create a xml file with name sales_order_create_load_block_shipping_method.xml on your module's layout folder and set template for this "order.create.shipping.method.form" and use your template file location as per the requirement.

Related Topic