Developer quick start
Connect a client’s custom plugin (loyalty points, delivery slots, a B2B price list, anything) to the cart, mini cart, checkout and thank-you templates, without editing the templates.
What you get:
- An Integrations card with your own on/off switches, saved and cleaned with the plugin’s settings, and changeable by the AI abilities.
- Texts on the Text & translations screen, in the shopper’s language, with WPML, Polylang, .mo files and the site owner’s edits.
- Template actions at every useful spot of the four templates.
- Filters for settings, texts, the design CSS, the mini cart refresh and what shoppers may change on a cart item.
- A small JavaScript API for the mini cart.
API level: NBWT_API_VERSION (currently 1). It goes up whenever a public function, hook or JS method is added.
A complete example#
Drop it in wp-content/plugins/acme-loyalty-nahnu/acme-loyalty-nahnu.php:
<?php
/**
* Plugin Name: Acme Loyalty for Nahnu Templates
*/
add_action( 'nbwt_register', function () {
// 1. A card on the Integrations tab, with two switches.
nbwt_register_integration( 'acme-loyalty', [
'name' => 'Acme Loyalty',
'description' => 'Shows the points a shopper earns in the cart, mini cart and thank-you page.',
'active' => function () { return class_exists( 'Acme_Loyalty' ); },
'url' => 'https://acme.example/loyalty/',
'settings_url' => admin_url( 'admin.php?page=acme-loyalty' ),
'settings' => [
'cart_points' => [ 'label' => 'Points in the cart and mini cart', 'help' => 'Under each item.', 'default' => true ],
'thankyou_points' => [ 'label' => 'Points on the thank-you page', 'default' => true ],
],
] );
// 2. Texts the site owner can edit and translate.
nbwt_register_texts( 'acme_loyalty', [
'label' => 'Acme Loyalty',
'text_domain' => 'acme-loyalty',
'en' => [ 'earn' => 'Earn %d points', 'earned' => 'You earned %d points with this order.' ],
'ar' => [ 'earn' => 'اكسب %d نقطة', 'earned' => 'ربحت %d نقطة من هذا الطلب.' ],
] );
} );
// 3. Print in the templates.
add_action( 'nbwt_cart_item_after', 'acme_points_line', 10, 2 );
add_action( 'nbwt_mini_cart_item_after', 'acme_points_line', 10, 2 );
function acme_points_line( $item, $key ) {
if ( ! nbwt_integration_active( 'acme-loyalty' ) || ! nbwt_integration_on( 'acme-loyalty', 'cart_points' ) ) {
return;
}
$points = (int) floor( $item['line_total'] );
echo '<p class="acme-points">' . esc_html( sprintf( nbwt_text( 'acme_loyalty', 'earn' ), $points ) ) . '</p>';
}
add_action( 'nbwt_thankyou_main_after', function ( $order ) {
if ( ! nbwt_integration_on( 'acme-loyalty', 'thankyou_points' ) ) {
return;
}
$points = (int) floor( $order->get_total() );
echo '<div class="wcty__card acme-points-card"><p>' . esc_html( sprintf( nbwt_text( 'acme_loyalty', 'earned' ), $points ) ) . '</p></div>';
} );
// 4. Style it with the templates' own tokens (brand color, dark mode and framework colors follow).
add_filter( 'nbwt_design_css', function ( $css ) {
return $css . '.acme-points{margin:4px 0 0;font-size:13px;color:var(--wcx-accent)}.acme-points-card{padding:var(--wcx-space-l)}';
} ); Always register on nbwt_register. It fires early on init, so your switches and texts are ready on every page, in the admin, in AJAX calls and for the AI abilities. Guard calls from code that may run without this plugin with function_exists( 'nbwt_register_integration' ) or defined( 'NBWT_API_VERSION' ).
Checklist for a client integration#
- Register on
nbwt_register, with anactivecallable that checks the client plugin. - Put every shopper-facing string in
nbwt_register_texts()and print it withnbwt_text(). - Check
nbwt_integration_active()andnbwt_integration_on()before printing. - Escape everything you print.
- Style with the
--wcx-*tokens throughnbwt_design_css, not a separate stylesheet on every page. - Test in English and Arabic (right to left), light and dark, and on a phone. Give your English texts the same wording as the plugin’s where the meaning is the same, so they pick up the built-in translations.