Xgenious/ docs
Products
Get support

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

HookTypeArgumentsNotes
nazmart:before_add_to_cartFilter$itemReturn false to block the add-to-cart.
nazmart:after_add_to_cartAction$item, $cartItem successfully added to cart.
nazmart:cart_item_removedAction$itemItem removed from cart.
nazmart:cart_quantity_changedAction$itemItem quantity updated.
nazmart:cart_totalFilter$totalModify the cart grand total (surcharges, discounts).
nazmart:cart_clearedActionnoneCart was emptied.

Order Hooks

HookTypeArgumentsNotes
nazmart:before_order_createFilter$order_dataReturn false to abort order creation.
nazmart:after_order_createAction$orderOrder record persisted to database.
nazmart:order_status_changedAction$order, $old_status, $new_statusAny status transition.
nazmart:order_completedAction$orderOrder moved to "completed" state.
nazmart:order_cancelledAction$orderOrder cancelled by customer or admin.
nazmart:order_refundedAction$order, $amountPartial or full refund issued.

Payment Hooks

HookTypeArgumentsNotes
nazmart:before_paymentFilter$payment_dataModify payment data before gateway call.
nazmart:payment_initiatedAction$payment, $orderPayment request sent to gateway.
nazmart:payment_successAction$payment, $orderGateway confirmed successful payment.
nazmart:payment_failedAction$payment, $order, $error_messageGateway returned failure.
nazmart:payment_pendingAction$payment, $orderAwaiting async gateway confirmation.
nazmart:payment_refundedAction$payment, $orderGateway confirmed refund.

Product Hooks

HookTypeArgumentsNotes
nazmart:product_priceFilter$price, $productModify displayed/calculated price.
nazmart:before_product_saveFilter$data, $productModify product data before DB write.
nazmart:after_product_saveAction$product, $actionProduct saved. $action is 'create' or 'update'. Use to invalidate feed caches or sync external catalogs.
nazmart:product_in_stockFilter$bool, $productOverride stock availability check.

User / Auth Hooks

HookTypeArgumentsNotes
nazmart:user_registeredAction$userNew customer account created.
nazmart:before_loginFilter$credentialsReturn false to block login attempt.
nazmart:after_loginAction$userCustomer successfully authenticated.

Content Filters

HookTypeArgumentsNotes
nazmart:render_product_cardFilter$html, $productModify product card HTML output.
nazmart:render_checkout_formFilter$htmlModify checkout form HTML.
nazmart:render_order_emailFilter$html, $orderModify order confirmation email body.

Frontend Layout Actions

HookFires at
nazmart:frontend_headJust after <head> opens
nazmart:frontend_head_endJust before </head> closes
nazmart:frontend_body_startJust after <body> opens
nazmart:frontend_footerJust before </body> closes

User Dashboard Hooks

These hooks let plugins add content to the customer-facing user dashboard (logged-in shop customers, not admin):

HookTypeArgumentsFires at
nazmart:user_dashboard_sidebarActionnoneInside the sidebar <ul>, before the logout link. Echo one or more <li> elements.
nazmart:user_dashboard_homeAction$userAfter 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:

HookTypeDescription
nazmart:price_plan_featuresFilterAdd a feature key/label to the pricing plan feature list.
nazmart:pagebuilder_tenant_addonsFilterRegister addon class names for tenant PageBuilder.
nazmart:pagebuilder_landlord_addonsFilterRegister addon class names for landlord PageBuilder.
nazmart:widgetbuilder_addonsFilterRegister widget class names for Widget Builder.
nazmart:megamenu_itemsFilterAdd class names that provide mega menu sections.
Still stuck?
Our support team is ready to help you get set up.
Get support