I'm using Commerce, and Orders can have a custom field on them. I need customers to be able to update that field from a front end form. I can't use the built in contoller for Orders because that requires Admin users.

1 Answer 1


Create a new plugin with a new controller class that enables this.



namespace Craft;
class MyPlugin extends BasePlugin
    ... the usual stuff from https://pluginfactory.io/ etc ...


namespace Craft;

class My_OrdersController extends BaseController

    public function actionUpdateOrder()
        // basic security precautions

        // get the fields
            $orderNumber = craft()->request->getPost('orderNumber');
            $customField = craft()->request->getPost('customField');
            $order       = craft()->commerce_orders->getOrderByNumber($orderNumber);

        // do the stuff
            if ($order &&
                $order->customer->userId == craft()->userSession->getUser()->id &&
                $customField != '')

                    // Lets also change the Order Status
                        $order->orderStatusId = 3; // this line changes the Status if wanted. Use the ID of the custom status.
                        $order->message = "Order status changed to 'To be cancelled' by customer";


Front end form:

<form action="" method="POST">
    <input type="hidden" name="action" value="myplugin/orders/updateOrder">
    <input type="hidden" name="redirect" value="shop/customer/order?number={{ number }}">
    <input type="hidden" name="orderNumber" value="{{ number }}"> 

        <span>Custo Field</span>
        <input type="text"
                value="{{ order.customField }}"
    <input type="submit" class="button warning" value="Confirm"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.