How to disable email sending when programatically creating an order in Magento

How to disable email sending when programatically creating an order in Magento

Here is a little snippet of code that can come in handy if you are like me handling a task of programatically creating an order in Magento. My issue was that I had to disable emails beeing sent out to the customers, while at the same time leave the normal frontend process. Thus I could not just go under Magento admin System > Congifuration and disable email sending from there.

Here is the sample line code you just need to place above final $order->save() or possibly $checkout->saveOrder():

Mage::app()->getStore()->setConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_ENABLED, "0");

You made it all the way down here so you must have enjoyed this post! You may also like:

Enabling Multi-part MIME Emails in Magento Tomislav Nikcevski
Tomislav Nikcevski, | 3

Enabling Multi-part MIME Emails in Magento

Extending “Contact us” functionality in Magento Ivan Bernatovic
Ivan Bernatovic, | 8

Extending “Contact us” functionality in Magento

Magento’s transactional eMails do-s and don’t-s Adrian Bece
Adrian Bece, | 10

Magento’s transactional eMails do-s and don’t-s

11 comments

  1. Hi, do you know how can I disable confirmation email when I creat order via API? Your code doesn’t work for API.

  2. My magento site are not work email correctly when order the product from customer.Who’s will you help me?

  3. @robin

    This worked for me

    Mage::app()->getStore()->setConfig(Mage_Customer_Model_Customer::XML_PATH_REGISTER_EMAIL_TEMPLATE, "0");
    				Mage::app()->getStore()->setConfig(Mage_Customer_Model_Customer::XML_PATH_REGISTER_EMAIL_IDENTITY, "0"); 

    in a custom customer.php file we have. Worked for my english store, but not in my french store. ;P

  4. @robin

    sure you can…
    try to trace the code in the class:

    Mage_Customer_Model_Customer

    and trace which XML_PATH you need

  5. Can I disable the welcome e-mail?
    I have a silent account creation so customers don’t need to register explicitly, but an account is made so they can check their order status.
    They receive 3 e-mails when placing an order: welcome email, separate password email and confirmation email

  6. Can I disable the Order Confirmation email only ?

    Customers receive 3 auto emails.

    Order confirmation, order complete & Order shipped.

    latter are processed at the same time and are redundant.

    Thanks –

  7. Hi,

    thanks for sharing this tip, but I havea slightly different problem and maybe you can help.

    When I’m enabling the ordermail system-> configuration -> Sales Email -> Order
    both the customer and the admin get the same email.

    But I just want the admin to get the email because theres another backend sending the emails to the customer.

    Do you have an idea?

  8. Interestingly this doesn’t seem to work with the newsletter subscription. The email is still sent.

    Mage::app()->getStore()->setConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_ENABLED, "0");
    Mage::getModel('newsletter/subscriber')->subscribe('example@example.com');

    This is on CE 1.4.

  9. @Jonathan
    Config is not saved so you don’t need to turn anything back. This code is merely used to overide saved config value at the moment you need it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.