Hook System
Nazmart's hook system is modelled after WordPress actions and filters. Hooks decouple core code from plugin extensions.
Global Helper Functions
- do_action(string $hook, ...$args): void — Fire an action hook. All registered callbacks for this hook are called in priority order. Return values are ignored.
- apply_filters(string $hook, mixed $value, ...$args): mixed — Pass a value through a chain of filter callbacks. Returns the final modified value.
- has_action(string $hook): bool — Check whether any callbacks are registered for a hook.
Priority
- Lower number = runs earlier. Default priority is 10.
- Use priority < 10 to run before core callbacks, > 10 to run after.
- Callbacks with the same priority run in the order they were registered.
Filters Must Return a Value
Warning
⚠️ Critical: Filter callbacks must always return a value. Forgetting return $value passes null to the next callback, silently breaking the filter chain.
Example: Adding a Filter in boot()
public function boot(): void
{
// Filter the cart total — add a surcharge
$this->add_filter('nazmart:cart_total', function (float $total) {
$surcharge = $this->get_option('surcharge_percent', 0);
return $total * (1 + $surcharge / 100);
}, 20);
// Action — fire and forget
$this->add_action('nazmart:after_order_create', function ($order) {
// notify Slack, push to CRM, etc.
\Log::info('Order created: ' . $order->id);
});
}
Commerce Hooks Reference
These hooks are fired by the Nazmart core at the appropriate moments. Prefix: nazmart:.
Cart Hooks
| Hook | Type | Arguments | Notes |
|---|---|---|---|
nazmart:before_add_to_cart | Filter | $item | Return false to block the add-to-cart. |
nazmart:after_add_to_cart | Action | $item, $cart | Item successfully added to cart. |
nazmart:cart_item_removed | Action | $item | Item removed from cart. |
nazmart:cart_quantity_changed | Action | $item | Item quantity updated. |
nazmart:cart_total | Filter | $total | Modify the cart grand total (surcharges, discounts). |
nazmart:cart_cleared | Action | none | Cart was emptied. |
Order Hooks
| Hook | Type | Arguments | Notes |
|---|---|---|---|
nazmart:before_order_create | Filter | $order_data | Return false to abort order creation. |
nazmart:after_order_create | Action | $order | Order record persisted to database. |
nazmart:order_status_changed | Action | $order, $old_status, $new_status | Any status transition. |
nazmart:order_completed | Action | $order | Order moved to "completed" state. |
nazmart:order_cancelled | Action | $order | Order cancelled by customer or admin. |
nazmart:order_refunded | Action | $order, $amount | Partial or full refund issued. |
Payment Hooks
| Hook | Type | Arguments | Notes |
|---|---|---|---|
nazmart:before_payment | Filter | $payment_data | Modify payment data before gateway call. |
nazmart:payment_initiated | Action | $payment, $order | Payment request sent to gateway. |
nazmart:payment_success | Action | $payment, $order | Gateway confirmed successful payment. |
nazmart:payment_failed | Action | $payment, $order, $error_message | Gateway returned failure. |
nazmart:payment_pending | Action | $payment, $order | Awaiting async gateway confirmation. |
nazmart:payment_refunded | Action | $payment, $order | Gateway confirmed refund. |
Product Hooks
| Hook | Type | Arguments | Notes |
|---|---|---|---|
nazmart:product_price | Filter | $price, $product | Modify displayed/calculated price. |
nazmart:before_product_save | Filter | $data, $product | Modify product data before DB write. |
nazmart:after_product_save | Action | $product, $action | Product saved. $action is 'create' or 'update'. Use to invalidate feed caches or sync external catalogs. |
nazmart:product_in_stock | Filter | $bool, $product | Override stock availability check. |
User / Auth Hooks
| Hook | Type | Arguments | Notes |
|---|---|---|---|
nazmart:user_registered | Action | $user | New customer account created. |
nazmart:before_login | Filter | $credentials | Return false to block login attempt. |
nazmart:after_login | Action | $user | Customer successfully authenticated. |
Content Filters
| Hook | Type | Arguments | Notes |
|---|---|---|---|
nazmart:render_product_card | Filter | $html, $product | Modify product card HTML output. |
nazmart:render_checkout_form | Filter | $html | Modify checkout form HTML. |
nazmart:render_order_email | Filter | $html, $order | Modify order confirmation email body. |
Frontend Layout Actions
| Hook | Fires at |
|---|---|
nazmart:frontend_head | Just after <head> opens |
nazmart:frontend_head_end | Just before </head> closes |
nazmart:frontend_body_start | Just after <body> opens |
nazmart:frontend_footer | Just before </body> closes |
User Dashboard Hooks
These hooks let plugins add content to the customer-facing user dashboard (logged-in shop customers, not admin):
| Hook | Type | Arguments | Fires at |
|---|---|---|---|
nazmart:user_dashboard_sidebar | Action | none | Inside the sidebar <ul>, before the logout link. Echo one or more <li> elements. |
nazmart:user_dashboard_home | Action | $user | After the four core stat cards on the dashboard home page. Receives the authenticated user object. Echo Bootstrap col <div> elements. |
Pair these hooks with a web route registered via register_web_routes(). See §12 for the full pattern.
Extension Hooks
These hooks let plugins integrate with built-in Nazmart subsystems:
| Hook | Type | Description |
|---|---|---|
nazmart:price_plan_features | Filter | Add a feature key/label to the pricing plan feature list. |
nazmart:pagebuilder_tenant_addons | Filter | Register addon class names for tenant PageBuilder. |
nazmart:pagebuilder_landlord_addons | Filter | Register addon class names for landlord PageBuilder. |
nazmart:widgetbuilder_addons | Filter | Register widget class names for Widget Builder. |
nazmart:megamenu_items | Filter | Add class names that provide mega menu sections. |
Still stuck?
Our support team is ready to help you get set up.

