Answers.Body: <p>There are a couple of options here.</p>
  
  <p><strong>Number 1</strong></p>
  
  <p>If you have the config setting <code>runQueueAutomatically</code> set to <code>false</code> you could call the controller action <code>queue/run</code> via ajax from your success page. This would trigger the queue to run.</p>
  
  <p><strong>Number 2</strong></p>
  
  <p>You can use the <code>EVENT_AFTER_COMPLETE_ORDER</code> event to run some custom code, in a module or plugin. In that code you can include <code>Craft::$app-&gt;getQueue()-&gt;run()</code> this will also trigger the queue to run. e.g. </p>
  
  <pre class="lang-php prettyprint-override"><code>Event::on(Order::class, Order::EVENT_AFTER_COMPLETE_ORDER, function(Event $e) {
      Craft::$app-&gt;getQueue()-&gt;run();
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-01T02:13:09.767Z
Answers.Text: I'm not extremely adept with the yii/php side of things in Craft, I'm assuming this would need to be wrapped into a module's functionality.
Answers.UserDisplayName: Anders
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-01T04:46:48.467Z
Answers.Text: ... Meaning inside an init() function or something like that.
Answers.UserDisplayName: Anders
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-02T07:32:00.163Z
Answers.Text: Yea @Anders that is right 
Answers.UserDisplayName: nfourtythree
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-02T21:33:04.403Z
Answers.Text: Figured it out, thanks!
Answers.UserDisplayName: Anders
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-03T15:49:20.623Z
Answers.Text: Can you share your solution?
Answers.UserDisplayName: Wonko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-03T13:22:22.467Z
Answers.LastActivityDate: 2020-02-03T13:22:22.467Z
Answers.UserDisplayName: nfourtythree
Answers.Body: <p>I like this solution:</p>
  <pre><code>{# run queue #}
  {% do craft.app.queue.handleResponse %}
  {{ craft.app.response.content|raw }}
  </code></pre>
  <p>Detailed in <a href="https://craftcms.stackexchange.com/questions/35606/craft-commerce-not-sending-e-mails-immediately">this post</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-12T12:10:54.617Z
Answers.LastActivityDate: 2021-07-12T12:10:54.617Z
Answers.UserDisplayName: outline4
Answers.Body: <p>Per request; I basically just dropped the code into the example module that comes with craft. I have some other modules and didn't want to clutter things. Here's the full code of the module;</p>
  
  <pre><code>&lt;?php
  namespace modules;
  
  use Craft;
  use craft\commerce\elements\Order;
  use yii\base\Event;
  
  /**
   * Custom module class.
   *
   * This class will be available throughout the system via:
   * `Craft::$app-&gt;getModule('my-module')`.
   *
   * You can change its module ID ("my-module") to something else from
   * config/app.php.
   *
   * If you want the module to get loaded on every request, uncomment this line
   * in config/app.php:
   *
   *     'bootstrap' =&gt; ['my-module']
   *
   * Learn more about Yii module development in Yii's documentation:
   * http://www.yiiframework.com/doc-2.0/guide-structure-modules.html
   */
  class Module extends \yii\base\Module
  {
      /**
       * Initializes the module.
       */
      public function init()
      {
          // Set a @modules alias pointed to the modules/ directory
          Craft::setAlias('@modules', __DIR__);
  
          // Set the controllerNamespace based on whether this is a console or web request
          if (Craft::$app-&gt;getRequest()-&gt;getIsConsoleRequest()) {
              $this-&gt;controllerNamespace = 'modules\\console\\controllers';
          } else {
              $this-&gt;controllerNamespace = 'modules\\controllers';
          }
  
          parent::init();
  
          // Custom initialization code goes here...
          Event::on(Order::class, Order::EVENT_AFTER_COMPLETE_ORDER, function(Event $e) {
              Craft::$app-&gt;getQueue()-&gt;run();
          });
      }
  }
  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-17T17:24:19.083Z
Answers.LastActivityDate: 2020-05-17T17:24:19.083Z
Answers.UserDisplayName: Anders
Body: <p>Curious if there is a way to fire order confirmation emails immediately? Basically how this was handled in Commerce 2.</p>
  
  <p>There are cases, and I'm dealing with one currently, where there is no command line access to the hosting or the possibility of setting up cron jobs and the likes to trigger the queue on an interval...</p>
  
  <p>Is there a workaround?</p>
  
Tags: <craft3><plugin-craftcommerce3>
Title: How does one get an order confirmation email to fire immediately in Commerce 3?
ThreadText: # How does one get an order confirmation email to fire immediately in Commerce 3?
  
  (Asked by: username_0 on 2020-01-31)
  
  Curious if there is a way to fire order confirmation emails immediately? Basically how this was handled in Commerce 2.
  
  There are cases, and I'm dealing with one currently, where there is no command line access to the hosting or the possibility of setting up cron jobs and the likes to trigger the queue on an interval...
  
  Is there a workaround?
  
  **Tags:** craft3, plugin-craftcommerce3
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2020-02-03. Score: 3 | Accepted answer
  
  There are a couple of options here.
  
  **Number 1**
  
  If you have the config setting `runQueueAutomatically` set to `false` you could call the controller action `queue/run` via ajax from your success page. This would trigger the queue to run.
  
  **Number 2**
  
  You can use the `EVENT_AFTER_COMPLETE_ORDER` event to run some custom code, in a module or plugin. In that code you can include `Craft::$app->getQueue()->run()` this will also trigger the queue to run. e.g.
  
  ```php
  Event::on(Order::class, Order::EVENT_AFTER_COMPLETE_ORDER, function(Event $e) {
      Craft::$app->getQueue()->run();
  });
  
  ```
  
  > **Comments:**
  > **username_0**: I'm not extremely adept with the yii/php side of things in Craft, I'm assuming this would need to be wrapped into a module's functionality.  
  > **username_0**: ... Meaning inside an init() function or something like that.  
  > **username_1**: Yea @username_0 that is right   
  > **username_0**: Figured it out, thanks!  
  > **username_2**: Can you share your solution?  
  
  ---
  
  ### Answer by username_3 on 2021-07-12. Score: 2
  
  I like this solution:
  
  ```
  {# run queue #}
  {% do craft.app.queue.handleResponse %}
  {{ craft.app.response.content|raw }}
  
  ```
  
  Detailed in [this post](https://craftcms.stackexchange.com/questions/35606/craft-commerce-not-sending-e-mails-immediately).
  
  
  ---
  
  ### Answer by username_0 on 2020-05-17. Score: 1
  
  Per request; I basically just dropped the code into the example module that comes with craft. I have some other modules and didn't want to clutter things. Here's the full code of the module;
  
  ```
  <?php
  namespace modules;
  
  use Craft;
  use craft\commerce\elements\Order;
  use yii\base\Event;
  
  /**
   * Custom module class.
   *
   * This class will be available throughout the system via:
   * `Craft::$app->getModule('my-module')`.
   *
   * You can change its module ID ("my-module") to something else from
   * config/app.php.
   *
   * If you want the module to get loaded on every request, uncomment this line
   * in config/app.php:
   *
   *     'bootstrap' => ['my-module']
   *
   * Learn more about Yii module development in Yii's documentation:
   * http://www.yiiframework.com/doc-2.0/guide-structure-modules.html
   */
  class Module extends \yii\base\Module
  {
      /**
       * Initializes the module.
       */
      public function init()
      {
          // Set a @modules alias pointed to the modules/ directory
          Craft::setAlias('@modules', __DIR__);
  
          // Set the controllerNamespace based on whether this is a console or web request
          if (Craft::$app->getRequest()->getIsConsoleRequest()) {
              $this->controllerNamespace = 'modules\\console\\controllers';
          } else {
              $this->controllerNamespace = 'modules\\controllers';
          }
  
          parent::init();
  
          // Custom initialization code goes here...
          Event::on(Order::class, Order::EVENT_AFTER_COMPLETE_ORDER, function(Event $e) {
              Craft::$app->getQueue()->run();
          });
      }
  }
  
  ```
  
  
  ---
  
  