<p>A customer can not update the order status from the front end. Only a user in the CP with the right permissions can do so from the Edit Order page.</p>
<p>To add this functionality you would need to make your own controller action endpoint (in a plugin or module) that does the following:</p>
<pre class="lang-php prettyprint-override"><code>&lt;?php

namespace modules\mymodule\controllers;

use modules\mymodule\MyModule;

use Craft;
use craft\web\Controller;

/**
 * @author    You
 * @package   MyModule
 * @since     1.0.0
 */
class UpdateOrderStatusController extends Controller
{
    protected $allowAnonymous = ['index'];

    /**
     * @return mixed
     */
    public function actionIndex()
    {
        $this-&gt;requirePostRequest();
        $this-&gt;requireAcceptsJson()
        // validate the current user is allowed to edit the order?

        $newStatusId = Craft::$app-&gt;getRequest()-&gt;getRequiredParam('statusId');
        $message = Craft::$app-&gt;getRequest()-&gt;getRequiredParam('message');
        $orderNumber = Craft::$app-&gt;getRequest()-&gt;getRequiredParam('number');
        $order = Order::find()-&gt;number($orderNumber)-&gt;one();

        if($order){
          $order-&gt;orderStatusId = $newStatusId;
          $order-&gt;message = $message;
          Craft::$app-&gt;getElements()-&gt;saveElement($order, false);
          return $this-&gt;asJson([
              'errors' =&gt; $order-&gt;getErrors(),
              'success' =&gt; !$order-&gt;hasErrors(),
          ]);
        }

        return $this-&gt;asJson([
            'errors' =&gt; ['No order found'],
            'success' =&gt; false,
        ]);
    }
}

</code></pre>

CC BY-SA 4.0
2020-07-30T11:43:50.950Z
2021-05-12T17:10:31.987Z
2021-05-12T17:10:31.987Z
Luke Holder
<p>Is there a way to edit an orders status via a frontend template?</p>

<plugin-craftcommerce3>
Commerce: How to update an order status via the frontend
# Commerce: How to update an order status via the frontend

(Asked by: username_0 on 2020-07-30)

Is there a way to edit an orders status via a frontend template?

**Tags:** plugin-craftcommerce3

---

## 1 answers

### Answer by username_1 on 2020-07-30. Score: 4 | Accepted answer

A customer can not update the order status from the front end. Only a user in the CP with the right permissions can do so from the Edit Order page.
To add this functionality you would need to make your own controller action endpoint (in a plugin or module) that does the following:
requirePostRequest();
        $this->requireAcceptsJson()
        // validate the current user is allowed to edit the order?

        $newStatusId = Craft::$app->getRequest()->getRequiredParam('statusId');
        $message = Craft::$app->getRequest()->getRequiredParam('message');
        $orderNumber = Craft::$app->getRequest()->getRequiredParam('number');
        $order = Order::find()->number($orderNumber)->one();

        if($order){
          $order->orderStatusId = $newStatusId;
          $order->message = $message;
          Craft::$app->getElements()->saveElement($order, false);
          return $this->asJson([
              'errors' => $order->getErrors(),
              'success' => !$order->hasErrors(),
          ]);
        }

        return $this->asJson([
            'errors' => ['No order found'],
            'success' => false,
        ]);
    }
}


---

