How to Generate Invoice with Pending Status in Magento 2
The default Magento 2 CMS manages orders and invoices effectively so as to ensure smooth online store functioning.
However, with increasing E-commerce facilities, the default features fall short. Fortunately, Magento 2 allows customizing the default features, for example, generate invoice with pending status in Magento 2.
To fulfill the modern requirements of online shoppers, you might have to offer varied payment methods such as cash on delivery, cheque, or money order.
When a customer chooses one of these payment methods while placing the order, the invoice is in a processing state. But, if you want to mark that order as pending until the payment is received, you can implement the below solution.
Method to Generate Invoice with Pending Status in Magento 2:
- Create file di.xml at app\code\Vendor\Extension\etc\ directory
1234<?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\OfflinePayments\Model\Checkmo" type="Vendor\Extension\Model\Checkmo" /></config> - Create file Checkmo.php at app\code\Vendor\Extension\Model\ directory
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960<?php/*** Copyright © Magento, Inc. All rights reserved.* See COPYING.txt for license details.*/namespace Vendor\Extension\Model;/*** Class Checkmo** @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface getExtensionAttributes()** @api* @since 100.0.2*/class Checkmo extends \Magento\Payment\Model\Method\AbstractMethod{const PAYMENT_METHOD_CHECKMO_CODE = 'checkmo';/*** Payment method code** @var string*/protected $_code = self::PAYMENT_METHOD_CHECKMO_CODE;/*** @var string*/protected $_formBlockType = \Magento\OfflinePayments\Block\Form\Checkmo::class;/*** @var string*/protected $_infoBlockType = \Magento\OfflinePayments\Block\Info\Checkmo::class;/*** Availability option** @var bool*/protected $_isOffline = true;protected $_canCapture = true;/*** @return string*/public function getPayableTo(){return $this->getConfigData('payable_to');}/*** @return string*/public function getMailingAddress(){return $this->getConfigData('mailing_address');}}
That’s it for generating invoice with pending status in Magento 2 store!
Any doubts? If so, mention them in the Comments section below. I’d be happy to help.
Do share the solution with Magento Community via social media.
Thank you.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
2 Comments
Hi
code is not working for me in magento 2.3.4
Hello Himanshu,
The above solution is working fine from our end.
Please make sure you have enabled the extension and run all the commands
Thank You