Is there any way to store checkout custom field data to checkout session? If possible how can I retrieve data?

Created an event

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_onepage_controller_success_action">
        <observer name="checkout_onepage_observer" instance="Mageplaza\HelloWorld\Observer\TestObserver" />

Observer code-

    namespace Oye\Deliverydate\Model\Observer;
    use Magento\Framework\Event\Observer as EventObserver;
    use Magento\Framework\Event\ObserverInterface;

     * Class SaveDeliveryDateToOrderObserver
     * @package Oye\Deliverydate\Model\Observer
    class SaveDeliveryDateToOrderObserver implements ObserverInterface
         * @var \Magento\Framework\ObjectManagerInterface
        protected $_objectManager;

         * @param \Magento\Framework\ObjectManagerInterface $objectmanager
        public function __construct(\Magento\Framework\ObjectManagerInterface $objectmanager)
            $this->_objectManager = $objectmanager;

         * @param EventObserver $observer
         * @return $this
        public function execute(EventObserver $observer)
            $order = $observer->getOrder();
            $quoteRepository = $this->_objectManager->create('Magento\Quote\Model\QuoteRepository');
            $quote = $quoteRepository->get($order->getQuoteId());
            $order->setDeliveryDate( $quote->getDeliveryDate() );
            //echo $quote->getDeliveryDate();
           // exit();



In the observer last line I tried to echo deliverydate custom field value using echo $quote->getDeliveryDate(); but not getting that value. Can I use session to store these custom checkout field value?

  • give more details at which location (model/controller/block) you are and what you try to save in session. – Hassan Ali Shahzad Oct 23 '18 at 7:29
  • If you have captche the custom field data at Magento checkout page then it is too tough to set save the data at session attribute – Amit Bera Oct 23 '18 at 8:02
  • Added More Details please check – Ragesh VP Oct 23 '18 at 8:42
  • $quote->getDeliveryDate() will not show anything unless you have saved Delivery Date in quote table. – Shashank Kumrawat Oct 23 '18 at 8:48
  • saved in quote table also – Ragesh VP Oct 23 '18 at 8:49

To know about use of checkout session you should check below link -


for more specific answer please share the exact event or requirement when you want to use checkout session.

| improve this answer | |
  • I added a custom field in magento 2 checkout page and data saved in quote table.How can I store these data in a custom table after checkout success?? – Ragesh VP Oct 23 '18 at 7:29
  • you need to use any event observer in your module after order success like sales_order_place_after or checkout_submit_all_after and then there you can save value in your custom table. – Shashank Kumrawat Oct 23 '18 at 7:35
  • for your help check this link – Shashank Kumrawat Oct 23 '18 at 7:35
protected $_checkoutSession;
public function __construct(
    public function __construct(
    \Magento\Checkout\Model\Session $checkoutSession
) {

    $this->_checkoutSession = $checkoutSession;

public function getCheckoutSession() 
    return $this->_checkoutSession;

You set a value :


You get a value :

$this->getCheckoutSession()->getVarValue(); //someValueHere

Then you unset the value :

| improve this answer | |

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.