OTP without DLT for WordPress and WooCommerce
You can add OTP without DLT to a WordPress or WooCommerce site with a small must-use plugin that calls DiOTP's REST API through wp_remote_post. Codes go out on DiOTP's registered DIORBT header and pre-approved OTP template, so you register nothing with DLT. DiOTP has no WordPress plugin: you add a short file of code yourself, and order or shipping SMS still need your own DLT template.
By Vivek Singh, Founder, Diorbit TechnologiesUpdated
Key facts
- Price
- ₹0.26 to ₹0.40 per OTP plus 18% GST, from a prepaid wallet. No setup fee, no monthly fee.
- Setup time
- Same day. Test on your own number in minutes, then go live.
- Sender name
- DIORBT, DiOTP's registered header (shown with an operator prefix, for example VM-DIORBT).
- Message
- "123456 is your login OTP for Your Company. Do not share it with anyone. Powered by Diorbit Technologies!" The wording is fixed; your company name fills the name slot.
- Compliance
- Sent under DiOTP's own registered DLT entity, header and pre-approved OTP template. You register nothing.
- Limits per number
- 1 code every 30 seconds, 3 per hour, 10 per day.
- Later
- Move to your own sender ID when your DLT registration is ready, with no code changes.
Is there a DiOTP plugin for WordPress?
No. DiOTP has no WordPress plugin, and there is no DiOTP listing in the plugin directory. What you get is the REST API, which a WordPress site can call with its own HTTP functions. This page shows how to do that for OTP without DLT: your codes are sent under DiOTP's own registered DLT entity, from the DIORBT header, on a pre-approved OTP template, so you can add phone verification to a store today without waiting for your own DLT approval.
A single file is an advantage here. It is easy to read and audit, it has no settings screen to misconfigure, and you can see exactly where your API key is used and what leaves your server. The file on this page is a must-use plugin with REST routes and nonces. It adds a verified mobile number to the WooCommerce registration form, lets returning customers log in with a code, holds cash-on-delivery orders until the phone is confirmed, and covers the trial errors. The last sections explain what is possible on Shopify, Google Forms and Zoho Forms, and which store messages the shared template cannot send.
Everything here uses wp_remote_post, so it needs no Composer packages. The SDKs page lists the official Node.js and Python packages if part of your stack runs outside WordPress.
The code below is a starting point for a developer. Test it on a staging copy of your site first. Code that touches sign-up and login deserves a careful look before it reaches your live store.
What will your shoppers see in the SMS?
On the shared template the sender is DIORBT, shown with an operator prefix such as VM-DIORBT, not your store name. The wording is fixed, and only the code and your company name change:
Text message
VM-DIORBT
482913 is your login OTP for Acme Store. Do not share it with anyone. Powered by Diorbit Technologies!
The company name slot holds up to 30 characters. Because the message says "login OTP", it fits account login and sign-up verification well. That is why the WooCommerce example below verifies the number at registration, not at checkout. Tell shoppers near the code box that the SMS comes from DIORBT, so they do not skip it while looking for your store's name. You can preview your own name in the OTP message preview.
How do you add OTP without DLT to WordPress, step by step?
- Create a DiOTP account and an API key. You get 10 free test messages, sent only to the mobile number you verified at sign-up.
- Add the key to wp-config.php as the DIOTP_API_KEY constant, so it never sits in the database or in a theme file.
- Create the folder wp-content/mu-plugins if it does not exist, and save the plugin file there as diotp-phone.php. Must-use plugins load on every request and cannot be switched off by mistake from the Plugins screen.
- Add the error function, then the WooCommerce hooks and the small script from this page to the same file.
- Open the My Account page in a private window, register with your own verified number and check that the code arrives and the account is created.
- Recharge your DiOTP wallet to go live, so the same key sends codes to any Indian mobile number.
Where does the API key go?
Put the key in wp-config.php as a constant. That file is outside your theme, is not exported with your content, and is not readable by visitors on a correctly set up server. Never paste the key into a theme file, a page builder field or a JavaScript snippet, because anything sent to the browser is public, and anyone with the key can spend your balance.
wp-config.php
// wp-config.php: add above the line that says "That's all, stop editing!"
define( 'DIOTP_API_KEY', 'diotp_live_xxxxxxxx' ); // your real key here, never in GitA must-use plugin with wp_remote_post and REST routes
The plugin registers two routes under /wp-json/diotp/v1: send and verify. Both check a WordPress nonce in a custom header before they do anything. The send route generates an Idempotency-Key with wp_generate_uuid4, so a retried request cannot text the shopper twice. The request_id is stored in a short-lived transient keyed by a random token in an HttpOnly cookie, so it never reaches the browser.
wp-content/mu-plugins/diotp-phone.php
<?php
/**
* Plugin Name: DiOTP phone check (must-use)
* Description: Sends and verifies OTPs through the DiOTP REST API. Site-specific code.
*/
defined( 'ABSPATH' ) || exit;
const DIOTP_NODLT_BASE = 'https://api-diotp.diorbit.com/v1';
/** One POST to DiOTP. Returns [status, decoded body]. */
function diotp_nodlt_call( $path, array $body, array $headers = array() ) {
if ( ! defined( 'DIOTP_API_KEY' ) ) {
return array( 500, array( 'error' => array( 'code' => 'missing_key' ) ) );
}
$res = wp_remote_post( DIOTP_NODLT_BASE . $path, array(
'timeout' => 10,
'headers' => array_merge( array(
'Authorization' => 'Bearer ' . DIOTP_API_KEY,
'Content-Type' => 'application/json',
), $headers ),
'body' => wp_json_encode( $body ),
) );
if ( is_wp_error( $res ) ) {
return array( 0, array( 'error' => array( 'code' => 'network_error' ) ) );
}
return array(
(int) wp_remote_retrieve_response_code( $res ),
(array) json_decode( wp_remote_retrieve_body( $res ), true ),
);
}
/** A random token in an HttpOnly cookie ties a browser to its pending code. */
function diotp_nodlt_token( $create = false ) {
$token = isset( $_COOKIE['diotp_t'] ) ? sanitize_key( wp_unslash( $_COOKIE['diotp_t'] ) ) : '';
if ( '' === $token && $create ) {
$token = strtolower( wp_generate_password( 32, false ) );
setcookie( 'diotp_t', $token, array(
'expires' => time() + HOUR_IN_SECONDS, 'path' => COOKIEPATH,
'secure' => is_ssl(), 'httponly' => true, 'samesite' => 'Lax',
) );
}
return $token;
}
add_action( 'rest_api_init', function () {
$nonce_ok = function ( WP_REST_Request $r ) {
return (bool) wp_verify_nonce( $r->get_header( 'x_diotp_nonce' ), 'diotp_nodlt' );
};
register_rest_route( 'diotp/v1', '/send', array(
'methods' => 'POST',
'permission_callback' => $nonce_ok,
'callback' => function ( WP_REST_Request $r ) {
$phone = preg_replace( '/\D/', '', (string) $r->get_param( 'phone' ) );
$phone = substr( $phone, -10 );
list( $status, $data ) = diotp_nodlt_call(
'/otp/send',
array( 'to' => $phone, 'country_code' => 91, 'channel' => 'sms', 'purpose' => 'signup' ),
array( 'Idempotency-Key' => wp_generate_uuid4() )
);
if ( 200 !== $status ) {
return diotp_nodlt_error( $status, $data );
}
$token = diotp_nodlt_token( true );
set_transient( 'diotp_rid_' . md5( $token ), array(
'rid' => $data['request_id'], 'phone' => $phone,
), 10 * MINUTE_IN_SECONDS );
return array( 'sent' => true );
},
) );
register_rest_route( 'diotp/v1', '/verify', array(
'methods' => 'POST',
'permission_callback' => $nonce_ok,
'callback' => function ( WP_REST_Request $r ) {
$token = diotp_nodlt_token();
$pending = $token ? get_transient( 'diotp_rid_' . md5( $token ) ) : false;
if ( ! $pending ) {
return new WP_Error( 'no_code', 'Please ask for a code first.', array( 'status' => 400 ) );
}
list( $status, $data ) = diotp_nodlt_call( '/otp/verify', array(
'request_id' => $pending['rid'],
'code' => sanitize_text_field( (string) $r->get_param( 'code' ) ),
) );
$code = $data['error']['code'] ?? '';
if ( 200 !== $status && 'already_verified' !== $code ) {
return diotp_nodlt_error( $status, $data );
}
delete_transient( 'diotp_rid_' . md5( $token ) );
set_transient( 'diotp_ok_' . md5( $token ), $pending['phone'], 30 * MINUTE_IN_SECONDS );
return array( 'verified' => true );
},
) );
} );Your server never sees the code itself. DiOTP generates it, stores it, expires it after 5 minutes and checks it, allowing 5 attempts. WordPress only keeps the request_id for 10 minutes and, after a successful check, a note that this browser verified this phone, for 30 minutes.
What the nonce does, and what it does not
The nonce stops another site from posting to your routes from a visitor's browser. It is not a rate limit: every logged-out visitor gets a working nonce from your page. DiOTP already limits each number to 1 code every 30 seconds, 3 per hour and 10 per day, and codes blocked by those limits are not charged. For a public form, add a bot check in front of the send button too. Our guide to SMS pumping protection explains why.
How should the plugin handle trial and template errors?
Add this function to the same file. It turns DiOTP's error reply into a WP_Error with a message the shopper can act on, and logs everything else for you.
diotp-phone.php (continued)
/** Turns a DiOTP error into a WP_Error the browser can show. */
function diotp_nodlt_error( $status, array $data ) {
$code = $data['error']['code'] ?? 'unknown';
$user = array(
'resend_cooldown' => 'Please wait 30 seconds before asking for another code.',
'phone_hourly_limit' => 'Too many codes for this number. Please try again in an hour.',
'phone_daily_limit' => 'Too many codes for this number today. Please try tomorrow.',
'invalid_request' => 'Please enter a valid 10 digit mobile number.',
'invalid_code' => 'That code is not right. Please check the SMS.',
'expired' => 'That code has expired. Please ask for a new one.',
'not_pending' => 'That code can no longer be used. Please ask for a new one.',
'too_many_attempts' => 'Too many wrong tries. Please ask for a new code.',
);
if ( isset( $user[ $code ] ) ) {
return new WP_Error( $code, $user[ $code ], array( 'status' => $status ) );
}
// trial_restricted, trial_used_up, insufficient_balance, unauthorized and the rest:
// a setup or account problem the shopper cannot fix. Log it for the site owner.
error_log( 'DiOTP error ' . $status . ' ' . $code );
return new WP_Error( 'otp_unavailable', 'We could not send a code right now. Please try again shortly.', array( 'status' => 503 ) );
}- trial_restricted (403): you are in test mode and the number is not the one you verified at sign-up. This is the most common surprise when you ask a colleague to test the form.
- trial_used_up (402): the 10 free test messages are spent. Recharge to go live.
- insufficient_balance (402): the wallet is empty on a live account. Shoppers see a generic message, so check your error log and recharge.
- resend_cooldown (429): a code went to this number less than 30 seconds ago. The script disables the send button for 30 seconds to match.
- template_not_available (422): the plugin passed a template id the account cannot use. The code above leaves template out, which uses the shared template.
The full list of codes and statuses is in the OTP API reference.
How do you require a verified number at WooCommerce registration?
These three hooks add a mobile number and code field to the My Account registration form, block registration until the number is verified, and save the verified number as the customer's billing phone. The check in woocommerce_register_post compares the posted number with the one this browser verified, so nobody can verify one number and register with another.
diotp-phone.php (WooCommerce hooks)
/* WooCommerce: require a verified mobile number on the My Account registration form. */
add_action( 'woocommerce_register_form', function () {
?>
<p class="form-row form-row-wide">
<label for="diotp_phone">Mobile number <span class="required">*</span></label>
<input type="tel" name="billing_phone" id="diotp_phone" inputmode="numeric" maxlength="10" />
<button type="button" id="diotp_send">Send code</button>
</p>
<p class="form-row form-row-wide">
<label for="diotp_code">Code from the SMS (sent by DIORBT)</label>
<input type="text" id="diotp_code" inputmode="numeric" autocomplete="one-time-code" />
<button type="button" id="diotp_check">Verify</button>
<span id="diotp_msg" role="status"></span>
</p>
<?php
} );
add_action( 'woocommerce_register_post', function ( $username, $email, $errors ) {
$phone = substr( preg_replace( '/\D/', '', wp_unslash( $_POST['billing_phone'] ?? '' ) ), -10 );
$token = diotp_nodlt_token();
$ok = $token ? get_transient( 'diotp_ok_' . md5( $token ) ) : false;
if ( ! $ok || $ok !== $phone ) {
$errors->add( 'diotp_unverified', 'Please verify your mobile number before creating an account.' );
}
}, 10, 3 );
add_action( 'woocommerce_created_customer', function ( $customer_id ) {
$token = diotp_nodlt_token();
$phone = $token ? get_transient( 'diotp_ok_' . md5( $token ) ) : '';
if ( $phone ) {
update_user_meta( $customer_id, 'billing_phone', $phone );
update_user_meta( $customer_id, 'diotp_verified_phone', $phone );
delete_transient( 'diotp_ok_' . md5( $token ) );
}
} );Finally, the page needs the nonce and a few lines of JavaScript to call the two routes. This prints both only on the My Account page, and only for visitors who are not signed in:
diotp-phone.php (front end)
/* Print the nonce and a small script on the My Account page only. */
add_action( 'wp_footer', function () {
if ( ! function_exists( 'is_account_page' ) || ! is_account_page() || is_user_logged_in() ) {
return;
}
$cfg = array(
'url' => esc_url_raw( rest_url( 'diotp/v1/' ) ),
'nonce' => wp_create_nonce( 'diotp_nodlt' ),
);
?>
<script>
(function (cfg) {
var msg = document.getElementById('diotp_msg');
function call(path, body) {
return fetch(cfg.url + path, {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json', 'X-DiOTP-Nonce': cfg.nonce },
body: JSON.stringify(body)
}).then(function (r) { return r.json(); });
}
document.getElementById('diotp_send').onclick = function (e) {
var btn = e.target;
call('send', { phone: document.getElementById('diotp_phone').value }).then(function (d) {
msg.textContent = d.sent ? 'Code sent. It comes from DIORBT.' : d.message;
if (d.sent) { btn.disabled = true; setTimeout(function () { btn.disabled = false; }, 30000); }
});
};
document.getElementById('diotp_check').onclick = function () {
call('verify', { code: document.getElementById('diotp_code').value }).then(function (d) {
msg.textContent = d.verified ? 'Number verified.' : d.message;
});
};
})(<?php echo wp_json_encode( $cfg ); ?>);
</script>
<?php
} );Keep the registration setting "Allow customers to create an account on the My account page" turned on in WooCommerce, or the form will not show. If your theme replaces the WooCommerce registration form, hook into its own form instead and keep the same server-side check.
Can returning customers log in to WooCommerce with an OTP?
Yes, once their number is on file as verified. Add this third route inside the same rest_api_init callback as send and verify. After a successful verify, the browser posts to /wp-json/diotp/v1/login, and the route signs the visitor in if a customer account holds that verified number.
diotp-phone.php (OTP login route)
/* OTP login for returning customers: add inside the same rest_api_init callback. */
register_rest_route( 'diotp/v1', '/login', array(
'methods' => 'POST',
'permission_callback' => $nonce_ok,
'callback' => function () {
$token = diotp_nodlt_token();
$phone = $token ? get_transient( 'diotp_ok_' . md5( $token ) ) : false;
if ( ! $phone ) {
return new WP_Error( 'unverified', 'Please verify your number first.', array( 'status' => 400 ) );
}
// Match only numbers saved as verified by an earlier check, never a typed billing phone.
$users = get_users( array(
'meta_key' => 'diotp_verified_phone',
'meta_value' => $phone,
'number' => 1,
'fields' => 'ID',
) );
delete_transient( 'diotp_ok_' . md5( $token ) );
if ( empty( $users ) ) {
return array( 'account' => false ); // offer registration with the number filled in
}
wp_set_current_user( (int) $users[0] );
wp_set_auth_cookie( (int) $users[0], true );
return array( 'account' => true );
},
) );Notice the login rule. The route matches only numbers saved as diotp_verified_phone by an earlier check, which the registration hooks above do for every new customer. A billing phone typed into a profile proves nothing, so it is never used to find an account. When the reply says account is false, offer to create an account for that number, or send the shopper to the registration form with the phone already filled in.
Existing customers who registered before you added the plugin need one signed-in check to link their number. A short prompt on the account dashboard, "Add your mobile number for faster login", is enough. After that, the phone and the code are all they need.
How do you confirm cash-on-delivery orders with an OTP?
COD orders placed with a wrong or fake number cost a store shipping both ways. A code sent to the billing phone straight after checkout catches many of them. This addition sends a code when a COD order reaches the thank-you page, puts the order on hold, and moves it to processing once the shopper types the code.
diotp-phone.php (COD confirmation)
/* WooCommerce: hold cash-on-delivery orders until the billing phone confirms a code. */
add_action( 'woocommerce_thankyou', function ( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order || 'cod' !== $order->get_payment_method() || $order->get_meta( '_diotp_rid' ) ) {
return; // not COD, or a code was already sent (a page refresh)
}
$phone = substr( preg_replace( '/\D/', '', $order->get_billing_phone() ), -10 );
list( $status, $data ) = diotp_nodlt_call(
'/otp/send',
array( 'to' => $phone, 'country_code' => 91, 'channel' => 'sms', 'purpose' => 'cod_confirmation' ),
array( 'Idempotency-Key' => 'cod-' . $order_id )
);
if ( 200 === $status ) {
$order->update_meta_data( '_diotp_rid', $data['request_id'] );
$order->update_status( 'on-hold', 'Waiting for COD phone confirmation.' );
$order->save();
}
} );
/* The code box on the thank-you page posts here with the order id and order key. */
add_action( 'rest_api_init', function () {
register_rest_route( 'diotp/v1', '/cod', array(
'methods' => 'POST',
'permission_callback' => '__return_true',
'callback' => function ( WP_REST_Request $r ) {
$order = wc_get_order( absint( $r->get_param( 'order_id' ) ) );
$key = sanitize_text_field( (string) $r->get_param( 'order_key' ) );
if ( ! $order || ! hash_equals( $order->get_order_key(), $key ) ) {
return new WP_Error( 'not_found', 'Order not found.', array( 'status' => 404 ) );
}
list( $status, $data ) = diotp_nodlt_call( '/otp/verify', array(
'request_id' => $order->get_meta( '_diotp_rid' ),
'code' => sanitize_text_field( (string) $r->get_param( 'code' ) ),
) );
if ( 200 !== $status ) {
return diotp_nodlt_error( $status, $data );
}
$order->update_status( 'processing', 'COD order confirmed by phone OTP.' );
return array( 'confirmed' => true );
},
) );
} );The order key check matters. Without it, anyone could post codes against any order number. WooCommerce already puts the order key in the thank-you page URL, so your code box can read it from there. Using the order id inside the Idempotency-Key means a refresh of the thank-you page can never send a second code for the same order.
Orders that stay on hold can go to your team for a call, which is kinder than cancelling a real customer who missed the message. One caution: on the shared template the SMS calls the code a login OTP, which reads oddly after a purchase. It works, but a COD template of your own reads better, as the table below explains.
Can you add OTP login to Shopify?
Not by replacing Shopify's login screen. Shopify runs its own customer login, and a theme edit cannot swap it for an SMS code check. These are the routes that do work:
- Order verification after checkout. A small app, or an app proxy that points at your own server, sends a DiOTP code to the phone on the order and records the result with a tag or note. Your team then ships only verified COD orders.
- Multipass, on Shopify Plus only. Your own site verifies the phone with DiOTP, then signs the customer into Shopify through Multipass.
- A headless storefront. If your shop front is your own app built on Shopify's storefront APIs, the login flow is your code, and the PHP OTP without DLT guide shows the server side.
Whichever route you pick, keep the API key on a server you control. Shopify theme files are delivered to every visitor, so a key placed in Liquid or theme JavaScript is effectively public.
Can Google Forms or Zoho Forms check an OTP?
Google Forms cannot call an outside API before a response is submitted, and has no field that checks a code. Apps Script can run on submit, but by then the response is already saved, so a script can flag a response but cannot block it. The practical answer is to verify the phone before the form, on a page you control:
- Build a small page on your WordPress site with the phone field and code box, backed by the send and verify routes above.
- After a successful verify, collect the rest of the answers on that same page.
- Write the submission into a Google Sheet from your server with the Sheets API, so your team keeps working in the sheet it knows.
Do not pass a "verified" flag into a pre-filled Google Form link: anyone can edit a pre-filled value before submitting. Zoho Forms has its own field options, which depend on your plan, so check Zoho's current documentation first. To send the code through DiOTP instead, the same principle applies: verify on your own page first, or have your server receive the submission and confirm the number afterwards.
Which WooCommerce messages need your own DLT template?
This is where store owners get caught out. The shared template sends OTPs that read "login OTP" and nothing else. Every other SMS a store sends is a different message type, and under TRAI's DLT rules it needs your own registered header and template, whichever provider you use.
| Message | Shared template? | Why |
|---|---|---|
| Sign-up and login codes | Yes | This is what the shared template is for. |
| Order placed or confirmed | No | A transactional message: needs your own DLT template. |
| Shipped, out for delivery, delivered | No | Order updates: need your own DLT template. |
| Delivery handover code | Works, reads oddly | The SMS would call it a login OTP. Your own template reads better. |
| Cash-on-delivery confirmation code | Works, reads oddly | Same reason: use your own template when you can. |
| Abandoned cart, back in stock, offers | No | Promotional: needs your own DLT registration and a promotional template. |
WooCommerce itself sends order emails, not SMS. If you add order SMS later, register your own entity, header and templates first; the DLT registration guide walks through it. When your registration is approved, add your entity ID, header and template ID under Sender IDs in the DiOTP dashboard. The must-use plugin above keeps working with no code change, and your OTPs then go out under your own header. You can keep using the shared template while your registration is in review. For more on stores, see OTP without DLT for ecommerce.
Questions and answers
Does DiOTP have a WordPress plugin?
No. DiOTP has no WordPress plugin. You add a short must-use plugin file yourself that calls the DiOTP REST API with wp_remote_post, as shown on this page.
Do I need DLT registration to send OTP from WooCommerce?
Not for login and sign-up codes. DiOTP sends them under its own registered DLT entity, the DIORBT header and a pre-approved OTP template. Order and shipping SMS still need your own DLT registration.
Where should I put the DiOTP API key in WordPress?
In wp-config.php as the DIOTP_API_KEY constant. Never put it in a theme file, a page builder field, the database or any JavaScript that reaches the browser.
Can I send WooCommerce order updates on the shared template?
No. The shared template only sends OTPs that read as a login OTP. Order confirmations, shipping updates and promotions need your own DLT header and templates.
Why does my test SMS not reach a colleague's phone?
A new account is in test mode, and the 10 free test messages go only to the mobile number verified at sign-up. The API returns trial_restricted. Recharge your wallet to go live.
Can I add OTP login to Shopify with DiOTP?
Not by replacing Shopify's own login screen. You can verify phones on orders through an app or app proxy, sign customers in through Multipass on Shopify Plus, or build a headless storefront.
Can Google Forms check an OTP before submission?
No. Google Forms cannot call an outside API before a response is saved. Verify the phone on a page you control first, then store the answers in a Google Sheet from your server.
Will the plugin change when I get my own sender ID?
No. You add your entity ID, header and template ID under Sender IDs in the DiOTP dashboard, and the same plugin keeps sending, now under your own header.
