WooCommerce
Bangla order confirmation calls for WooCommerce
নতুন অর্ডার এলেই ক্রেতাকে বাংলায় কল যায়। অর্ডার কনফার্ম হলো কি না আর ঠিকানা, দুটোই ফিরে আসে আপনার WooCommerce-এ।
Connect a WooCommerce COD order confirmation call to your shop in Bangladesh. A plugin built on the Sworborno API sends each order and brings the result back.
For shop owners: WooCommerce order verification before you ship
A fake COD order can cost you the delivery charge. With a plugin built on the Sworborno API, every new order is checked before you ship: Sworborno calls the buyer in Bangla, reads the order back, asks them to confirm or cancel, and checks the address. The result lands on the WooCommerce order as a status and a note, and held orders wait for your staff.
Building a WooCommerce fraud prevention plugin? Pair the call with a courier fraud check: the buyer’s delivery history and what they say on the call today tell you different things.
What the shop sets up
Sign up → ask Sworborno to switch calling on → top up minutes → create a key as the account’s owner or admin → paste it into your plugin → paste the plugin’s webhook address into Sworborno and copy the signing secret into the plugin.
Sworborno does not publish its own WooCommerce or WordPress plugin. WooCommerce developers build plugins on the API, and a WordPress developer can connect a shop directly. A WooCommerce COD plugin built on the API needs only the shop’s API key and one webhook address; the signing secret verifies returned results.
What each result does to the WooCommerce order
| Call result | What happened | Order status the sketch sets | What staff do |
|---|---|---|---|
confirmed | Buyer confirmed; thana and district saved when returned. | Processing (processing) | Pack and ship. |
hold + cancelled | Buyer does not want the order. | On hold (on-hold) | Check, then cancel by hand. Never auto-cancel. |
hold + modified | Buyer wants a change. | On hold (on-hold) | Apply the change from the summary. |
hold + no_answer | Nobody answered any attempt. | On hold (on-hold) | Call the same order again later. |
hold + wrong_number, unclear or any other reason | Wrong person, no clear answer or another issue. | On hold (on-hold) | A person checks. |
For developers: one queued job and one result route
These PHP examples are a sketch, not a finished plugin. Open each step for the code. The integration guide has the full request and result fields; GitHub has copy-ready API examples.
1. Save the shop’s settings
Store the API key and signing secret with update_option, with autoload off. Protect the admin form with a capability check and a nonce. Show the webhook address from rest_url; the shop saves it in Settings → API keys → Result webhook and copies the signing secret back into your plugin. The secret is shown once.
// Inside your settings form's save handler, after submitting wp_nonce_field().
if ( ! current_user_can( 'manage_woocommerce' ) ) {
wp_die( 'Not allowed.' );
}
check_admin_referer( 'your_plugin_settings' );
update_option( 'your_plugin_api_key',
sanitize_text_field( wp_unslash( $_POST['api_key'] ?? '' ) ), false );
update_option( 'your_plugin_signing_secret',
sanitize_text_field( wp_unslash( $_POST['signing_secret'] ?? '' ) ), false );
// Show this URL in the settings screen; never show the saved secrets publicly.
echo esc_url( rest_url( 'your-plugin/v1/sworborno-result' ) );2. Queue new COD orders
Hook classic and block checkout. Action Scheduler ships with WooCommerce. Never call the API inside checkout: a slow or failed request should not make the buyer wait. Both hooks can queue safely because the same external_id makes just one call.
function your_plugin_queue_call( $order_id ) {
$order = wc_get_order( $order_id );
if ( $order && 'cod' === $order->get_payment_method() ) {
as_enqueue_async_action( 'your_plugin_send_call', array( $order_id ) );
}
}
add_action( 'woocommerce_checkout_order_processed', 'your_plugin_queue_call' );
add_action( 'woocommerce_store_api_checkout_order_processed', function ( $order ) {
your_plugin_queue_call( $order->get_id() );
} );3. Send from the queued job
Use the order id as a string for external_id and context.order_id. This sketch uses billing details; choose the delivery address your shop actually uses and include any fees in the order context. A 202 means accepted. Throw on failure so Action Scheduler records it; arrange retries with the same id and show failed actions to the shop. Throwing alone does not schedule a retry.
add_action( 'your_plugin_send_call', function ( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order || 'cod' !== $order->get_payment_method() ) { return; }
$items = array();
foreach ( $order->get_items() as $item ) {
$items[] = array( 'name' => $item->get_name(),
'qty' => $item->get_quantity(),
'price' => (float) $order->get_item_total( $item, true ) );
}
$body = array(
'external_id' => (string) $order_id,
'phone' => $order->get_billing_phone(),
'context' => array(
'customer_name' => $order->get_formatted_billing_full_name(),
'order_id' => (string) $order_id,
'total' => (float) $order->get_total(),
'payment_method' => $order->get_payment_method(),
'address' => implode( ', ', array_filter( array(
$order->get_billing_address_1(), $order->get_billing_address_2(),
$order->get_billing_city(), $order->get_billing_state(),
$order->get_billing_postcode() ) ) ),
'delivery_charge' => (float) $order->get_shipping_total()
+ (float) $order->get_shipping_tax(),
'items' => $items,
),
);
$response = wp_remote_post(
'https://www.sworborno.com/api/v1/integrations/call-requests', array(
'headers' => array( 'Authorization' => 'Bearer ' . get_option( 'your_plugin_api_key' ),
'Content-Type' => 'application/json' ),
'body' => wp_json_encode( $body ), 'timeout' => 10,
) );
if ( is_wp_error( $response ) || 202 !== wp_remote_retrieve_response_code( $response ) ) {
throw new RuntimeException( 'Call request failed; review the scheduled action.' );
}
$order->add_order_note( 'Sworborno accepted the confirmation call request.' );
} );4. Verify and save the result
Check X-Signature against the timestamp and raw body, reject timestamps more than 300 seconds away, then skip a repeated X-Webhook-Id. Branch on status only: confirmed → processing; hold → on-hold with the summary for staff. Save thana and zilla through order methods for HPOS. Keep the original address; let staff review changes.
add_action( 'rest_api_init', function () {
register_rest_route( 'your-plugin/v1', '/sworborno-result', array(
'methods' => 'POST', 'permission_callback' => '__return_true',
'callback' => 'your_plugin_receive_result',
) );
} );
function your_plugin_receive_result( WP_REST_Request $request ) {
$ts = $request->get_header( 'X-Webhook-Timestamp' );
$secret = get_option( 'your_plugin_signing_secret', '' );
$expected = hash_hmac( 'sha256', $ts . '.' . $request->get_body(), $secret );
if ( ! $secret || ! ctype_digit( (string) $ts ) || abs( time() - (int) $ts ) > 300
|| ! hash_equals( $expected, (string) $request->get_header( 'X-Signature' ) ) ) {
return new WP_Error( 'signature', 'Invalid signature or timestamp.', array( 'status' => 401 ) );
}
$id = $request->get_header( 'X-Webhook-Id' );
if ( ! $id ) {
return new WP_Error( 'missing_id', 'Missing webhook id.', array( 'status' => 400 ) );
}
$receipt = 'your_plugin_receipt_' . hash( 'sha256', $id );
if ( 'done' === get_option( $receipt ) ) { return new WP_REST_Response( null, 200 ); }
$lock = $receipt . '_lock';
// Keep the lock value fixed; completed receipts are stored separately.
if ( ! add_option( $lock, 'working', '', false ) ) {
return new WP_Error( 'busy', 'Delivery is being handled.', array( 'status' => 503 ) );
}
try {
if ( 'done' === get_option( $receipt ) ) { return new WP_REST_Response( null, 200 ); }
$data = json_decode( $request->get_body(), true, 512, JSON_THROW_ON_ERROR );
if ( 'balance.low' === ( $data['event'] ?? '' ) ) {
update_option( 'your_plugin_balance_low', true, false );
} elseif ( 'call.result' === ( $data['event'] ?? '' ) ) {
$order_id = (string) ( $data['order_id'] ?? '' );
$status = $data['status'] ?? '';
$order = ctype_digit( $order_id ) ? wc_get_order( (int) $order_id ) : false;
if ( ! $order || ! in_array( $status, array( 'confirmed', 'hold' ), true ) ) {
throw new RuntimeException( 'Unknown order or status.' );
}
$summary = sanitize_text_field( $data['summary'] ?? '' );
foreach ( array( 'thana', 'zilla' ) as $field ) {
if ( isset( $data['address'][ $field ] ) ) {
$order->update_meta_data( '_sworborno_' . $field,
sanitize_text_field( $data['address'][ $field ] ) );
}
}
$order->save(); // Order methods also work with HPOS.
if ( 'confirmed' === $status ) {
$order->update_status( 'processing', 'Sworborno: ' . $summary );
} else {
$order->update_status( 'on-hold', $summary ); // Never auto-cancel.
}
}
update_option( $receipt, 'done', false );
} catch ( Throwable $error ) {
return new WP_Error( 'result_failed', 'Could not save result.', array( 'status' => 500 ) );
} finally {
delete_option( $lock ); // Let a failed delivery be tried again.
}
return new WP_REST_Response( null, 200 );
}Answer 200 quickly. Any non-2xx response is retried: immediately, then 30s, 2m, 10m, 30m, 2h and 6h. The sketch records webhook ids and prevents simultaneous writes; before shipping, add receipt cleanup, recovery for an interrupted write, and order-state rules for orders staff have already fulfilled or cancelled. Keep network work out of the result route.
5. Test with your own phones, then go live
Ask for the test assistant, which only calls your own phones. Check both checkouts, a repeated order submission, confirmed and held results, address changes, invalid signatures, old timestamps and duplicate webhook deliveries before sending real orders.
Questions before you start
- Only COD orders, or all orders?
The plugin decides which orders to send. The sketch below sends only cash-on-delivery orders; your developer can choose a different rule.
- Does this work with block checkout?
Yes. Hook both woocommerce_checkout_order_processed for classic checkout and woocommerce_store_api_checkout_order_processed for block checkout, then queue the same job.
- What if the buyer changes the address?
The call checks the address with the buyer and sends back the thana and district next to your original address, which is never overwritten. If the buyer wants a different product, size or quantity, the order comes back on hold with a short summary, so a person checks it before dispatch.
- What does a call cost?
Order calls cost ৳4 a minute, billed by the second from the shop’s own prepaid balance.
See pricing