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

Featured Image

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");

10 comments

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

  2. @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

  3. 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

  4. 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 –

  5. 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?

  6. 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.

  7. @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>.