How To Create an Order Module

Order modules can interact with orders and support several different behaviors.

This is an overview of an order module:

includes/modules/order/om_my_order_module.inc.php:


<?php

  class om_my_order_module {
    public $id = __CLASS__;
    public $name = 'My Order Module';
    public $description = 'Order module that does something with order data';
    public $version = '1.0';
    public $author = 'ACME Corp.';
    public $website = 'https://www.litecart.net';

    public function actions() {}

    public function validate($order) {}

    public function update($order) {}

    public function after_process($order) {}

    public function success($order) {}

    function settings() {
      return [
        [
          'key' => 'status',
          'default_value' => '1',
          'title' => 'Status',
          'description' => 'Enables or disables the module.',
          'function' => 'toggle("e/d")',
        ],
        [
          'key' => 'priority',
          'default_value' => '0',
          'title' => 'Priority',
          'description' => 'Process this module by the given priority value.',
          'function' => 'number()',
        ],
      ];
    }

    public function install() {}

    public function uninstall() {}
  }

actions()

The action() method can return a set of action buttons on the orders page that triggers certain methods upon click. Simply select orders from the list and click an action button.

    public function actions() {

      if (empty($this->settings['status'])) return;

      return [
        'id' => __CLASS__,
        'name' => 'My Actions',
        'description' => 'Click any button to perform an action',
        'actions' => [
          [
            'id' => 'firstbutton',
            'title' => 'My Button Text',
            'description' => 'Click this button to do something',
            'function' => 'my_fancy_method',
          ],
          // Action 2
          // Action 3
          // ...
        ],
      ];
    }

    public function my_fancy_method($order_ids) {

      foreach($order_ids as $order_id) {
        $order = new ent_order($order_id);
        // Custom code to do whatever
      }
    }

validate()

The validate method() is called during checkout during validations before the order is processed. An error message returned will prevent the customer from being able to checkout.

    public function validate($order) {
      return ['error' => 'This order is no good'];
    }

after_process()

The after_process() method is called during checkout after the order is saved to database.

    public function after_process($order) {
      // Do something ...
    }

success()

The success() method can output HTML on the order success page e.g. a sales tracker pixel or a receipt.

    public function success($order) {
      return '<script>...</script>';
    }

Revisions

Top Editors
Recently Edited Articles