cancel
Showing results for 
Search instead for 
Did you mean: 

In magneot 2.4.1 auto stop sending invoice email after complete payment without admin option

In magneot 2.4.1 auto stop sending invoice email after complete payment without admin option

Hi Guys,

I want to stop auto invoice email after complete payment, In admin there is already a option to stop invoice mail but if I disable that option in admin then when I send invoice by programmatically it does not work.

Any one have know how to achieve this?

Thanks

1 REPLY 1

Re: In magneot 2.4.1 auto stop sending invoice email after complete payment without admin option

Hello @webkeonsanjeev 

 

Steps to Stop Invoice Email Sending

If you don't already have a custom module, create one. For example, Vendor/Module

Create etc/module.xml

 

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_Module" setup_version="1.0.0" /> 
</config>

Override the Invoice Email Sending Logic

You will need to disable the email sending in the Invoice Service class.

Modify di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Sales\Model\Order\Email\Sender\InvoiceSender" type="Vendor\Module\Model\Email\Sender\CustomInvoiceSender" /> 
</config>

Create a Custom InvoiceSender

Create a custom class to override the email sending behavior.

Vendor/Module/Model/Email/Sender/CustomInvoiceSender.php

namespace Vendor\Module\Model\Email\Sender;

 

use Magento\Sales\Model\Order\Email\Sender\InvoiceSender as BaseInvoiceSender;

use Magento\Sales\Model\Order\Invoice;

 

class CustomInvoiceSender extends BaseInvoiceSender

{

    /**

     * Override to stop sending invoice emails

     *

     * @param Invoice $invoice

     * @param bool $forceSyncMode

     * @return bool

     */

    public function send(Invoice $invoice, $forceSyncMode = false)

    {

        // Prevent email from being sent by returning false

        return false;

    }

}

 

php bin/magento setup:upgrade 

php bin/magento cache:flush

 

 

 

​Hope it helps ! 

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

 

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9