Developer Guide: Extensibility & Add-ons (Pro)
WooCommerce Order Tracker Pro is designed with an "Add-on Architecture" that allows developers to extend the plugin without modifying the core files.
🏗️ Registering New Notification Channels
The plugin supports Email, SMS, and WhatsApp by default. You can add entirely new channels (e.g., Slack, Push) using the bot_active_channels filter.
add_filter('bot_active_channels', function($channels) {
$channels[] = 'slack';
return $channels;
});
When you add a new channel:
A new tab will automatically appear in the Notifications settings page.
A new notification toggle will appear in the Tracking Stages manager.
You must handle the rendering of the settings tab using
do_action("bot_render_notification_tab_{$active_tab}").
📱 Adding New SMS/WhatsApp Providers
If you want to use a provider other than Africa's Talking or Twilio, you can register it using the provider filters.
Example: Adding a custom SMS Provider
Register the Provider:
add_filter('bot_sms_providers', function($providers) {
$providers['my_custom_gateway'] = 'My Custom Gateway';
return $providers;
});
Render Configuration Fields: Use the
bot_render_sms_provider_fieldsaction to inject your API key fields into the settings page.
add_action('bot_render_sms_provider_fields', function($settings) {
?>
<tr data-provider="my_custom_gateway">
<th>API Key</th>
<td><input type="text" name="bot_notifications_sms[my_api_key]" value="<?php echo esc_attr($settings['my_api_key'] ?? ''); ?>"></td>
</tr>
<?php
});
Implement the Notifier: Create a class that implements
Blueness\WoocommerceOrderTracker\Notifications\Contracts\Notifierand register it viabot_notifier_factory_make.
🛠️ Factories and Custom Logic
The plugin uses factory patterns to create Notifiers and Notifications. You can intercept these to inject your own classes.
Custom Notifier Logic
add_filter('bot_notifier_factory_make', function($notifier, $channel) {
if ($channel === 'sms' && get_option('bot_notifications_sms')['provider'] === 'my_custom_gateway') {
return new MyCustomSmsNotifier();
}
return $notifier;
}, 10, 2);
Custom Notification Template Logic
add_filter('bot_notification_factory_make', function($notification, $channel, $order, $stage) {
if ($channel === 'email' && $stage['id'] === 'shipped') {
return new MyCustomShippedNotification($order, $stage);
}
return $notification;
}, 10, 4);
🚀 Implementation Examples
1. Creating a Custom Notification Class
A Notification class is responsible for preparing the content (Recipient, Subject, and Body).
use Blueness\WoocommerceOrderTracker\Notifications\Contracts\Notification;
class MyCustomShippedNotification implements Notification {
protected $order;
protected $stage;
public function __construct($order, array $stage) {
$this->order = $order;
$this->stage = $stage;
}
public function getRecipient(): string {
return $this->order->get_billing_email();
}
public function getSubject(): string {
return "Great news! Your order #" . $this->order->get_id() . " is on its way!";
}
public function getBody(): string {
return "Hello " . $this->order->get_billing_first_name() . ",\n\n" .
"Your order is now " . $this->stage['name'] . ".";
}
}
2. Creating a Custom Notifier Class
A Notifier class is responsible for the delivery of the notification (e.g., calling an external API).
use Blueness\WoocommerceOrderTracker\Notifications\Contracts\Notifier;
class MyCustomSmsNotifier implements Notifier {
protected $to;
protected $subject;
protected $body;
public function setTo(string $recipient): self {
$this->to = $recipient;
return $this;
}
public function setSubject(string $subject): self {
$this->subject = $subject;
return $this;
}
public function setBody(string $body): self {
$this->body = $body;
return $this;
}
public function send(): bool {
// Example: Call your custom SMS Gateway API
/*
$response = wp_remote_post('https://api.mygateway.com/send', [
'body' => [
'to' => $this->to,
'message' => $this->body,
'key' => get_option('wot_notifications_sms')['my_api_key']
]
]);
return !is_wp_error($response);
*/
return true;
}
}
List of Key Filters
Filter | Description |
|---|---|
| Define which notification channels are available. |
| Register new SMS gateways. |
| Register new WhatsApp Business API providers. |
| Customize the tabs on the notification settings page. |
| Modify the default message templates for new stages. |
| Override the notification object creation. |
| Override the notifier object creation. |