Custom Invoice Numbers

By default the invoice number is generated by the page number.

You can override this method to use a custom field.
To update the field a custom hook can be used.

Override invoiceNumber()

You can override the default invoiceNumber() method to return for example a content field. In this example the content of invoiceNumber field is returned.


class OrderPage extends OrderPageAbstract
  public function invoiceNumber(): string
    return $this->content()->invoiceNumber()->toString();

Be careful, the invoiceNumber() method has to return a string.

Update content field using a hook

To update the invoiceNumber content field you can use the completePayment:after hook.


return [
  'hooks' => [
    'ww.merx.completePayment:after' => function ($orderPage) {
      $invoiceNumber = 0;
      if ($prevOrder = $orderPage->prevListed()) {
        $invoiceNumber = (int)$prevOrder->invoiceNumber();
      $invoiceNumber = $invoiceNumber + 1;
        'invoiceNumber' => $invoiceNumber,

Return Invoice Number

To return the invoice number you should use the custom $orderPage->invoiceNumber() method.


echo 'Invoice Number: ';
echo $page->invoiceNumber();