In a Magento 2 store, the admin may want to configure multiple shipping addresses that allows customers to have their orders delivered to more than one address on the checkout page. Admin may need to add a custom field in multi shipping of the checkout page in Magento 2 store, i.e., Extra Fee.
While adding a custom field, it requires adding its value to the sales_order_table to validate that value. In that case, you need to override the event and observer. Events in Magento 2 are dispatched based on an action performed, and it passes data to the observer. Observers are Magento classes that are executed when an event is dispatched.
In that scenario, you need to use “checkout_type_multishipping_create_orders_single” event in Magento 2.
Method to Use “checkout_type_multishipping_create_orders_single” Event in Magento 2
1. Create event.xml file at Vendor\Module\etc
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_type_multishipping_create_orders_single">
<observer name="surcharge_to_order_multi" instance="Vendor\Module\Observer\MultiSurchargeOrder"/>
</event>
</config>
2. Create MultiSurchargeOrder.php file at Vendor\Module\Observer
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class MultiSurchargeOrder implements ObserverInterface
{
public function execute(Observer $observer)
{
// here you can add code to save in order tabel at time multi shippinging place order
}
}
Follow these steps and enhance the customer experience!
Feel free to share the solution with Magento Community via social media.
Thank You.