=== Shipping Labels for DHL eCommerce APAC ===

Author: Algoleap Technologies Pvt Ltd
Contributors: dhlecommerceasia
Tags: shipping, ecommerce, woocommerce, labels, dhl-shipping, tracking, webhook
Requires at least: 6.0
Tested up to: 6.6
Stable tag: 1.1.7
Requires PHP: 7.4
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
WC requires at least: 3.0
WC tested up to: 9.1.0
WC HPOS Compatible: true
Integrate DHL eCommerce APAC shipping services with your WooCommerce store. Supports High-Performance Order Storage (HPOS) and automated tracking updates through Webhooks.

== Description ==

The **Shipping Labels for DHL eCommerce APAC** plugin, developed by **Algoleap Technologies Pvt Ltd**, automates your shipping workflow by connecting your WooCommerce store to DHL eCommerce APAC services — with full support for **WooCommerce HPOS** and now **automatic tracking status updates via Webhooks**.

### Key Features ###
- Generate and print shipping labels directly from WooCommerce admin.
- Automatically track shipments and update order status via Webhooks.
- Offer DHL shipping options at checkout.
- Calculate accurate shipping rates based on destination, weight, and dimensions.
- Supports WooCommerce HPOS (High-Performance Order Storage).
- Easy-to-use interface for generating and printing shipping labels.
- Seamless integration with WooCommerce checkout process.
- Detailed documentation and support available.

== New in Version 1.1.7 ==

- **Fixed: Shipment ID Mapping Issue (HPOS / WooCommerce Order Number Compatibility)**  
  - Updated Shipment ID field to use the WooCommerce displayed **Order Number** instead of the internal database order ID.  
  - Ensures Shipment ID now matches the order number visible in WooCommerce admin.  
  - Improves compatibility with HPOS and Sequential Order Number configurations.  
  - Prevents mismatch between admin order display and generated shipment reference.

- **Fixed: Expired Token Issue (Critical Fix)**  
  - Removed dependency on manual **“Test Connection”** to generate access tokens.  
  - Implemented automatic token generation and refresh mechanism.  
  - Tokens are now regenerated automatically if expired (no user action required).  
  - Ensures bulk label creation, single label creation, update, and cancel actions work reliably at any time.

- **Improved: Bulk Label Stability**  
  - Bulk label creation now works even if the user has not recently authenticated.  
  - Prevents failures caused by missing or expired tokens.

- **Improved: System Reliability**  
  - Eliminates dependency on session-based or user-triggered token storage.  
  - Ensures consistent functionality across admin, bulk actions, and background processes.

- **Code Enhancement**  
  - Centralized token handling using a reusable helper function.  
  - Improved validation to prevent API calls with empty tokens.

== Installation ==

1. Upload the plugin to `/wp-content/plugins/shipping-labels-dhl-ecommerce-apac`, or install via the WordPress plugin screen.
2. Activate it via **Plugins > Installed Plugins**.
3. Go to **WooCommerce → Settings → Shipping → DHL eCommerce APAC** to configure.

**Note:** Always back up your site before updating the plugin.

== Configuration ==

1. Enter your **DHL eCommerce APAC API credentials**.
2. Configure your default package dimensions and shipping preferences.
3. Enable **Webhook tracking updates** (enabled automatically).
4. Enable debug logging if needed.

== Usage ==

### Creating Shipping Labels
1. Go to **WooCommerce → Orders**.
2. Open any order and find the “DHL eCommerce APAC” panel.
3. Fill in shipping details and click **Generate Label**.
4. Download and print the generated label.

### Bulk Label Creation
1. Go to **WooCommerce → Orders**.
2. Select multiple orders.
3. Choose **Create DHL eCommerce APAC Labels** from the Bulk Actions dropdown.

### Automatic Tracking Updates
- DHL’s ELR system automatically sends tracking updates to your webhook endpoint.
- The WooCommerce order table updates the **Tracking Status** automatically.

## WooCommerce HPOS Compatibility ##
Fully compatible with WooCommerce High-Performance Order Storage.

## Privacy & Logging ##
Webhook and API logs are stored securely in WooCommerce → Status → Logs (when enabled).

## Disclaimer ##
This plugin is an independent DHL eCommerce APAC integration and is not officially endorsed by DHL.

## Frequently Asked Questions ##

### Does this plugin support automatic tracking updates?  
Yes — tracking updates are pushed directly by DHL to your webhook endpoint.

### Do I need to manually configure the webhook?  
No — it is registered automatically when the plugin is activated.

### Does this work with HPOS?  
Yes, the plugin is fully compatible.

## Support ##
Contact the WordPress plugin support forum or plugins@wordpress.org.

## Changelog ##

1.1.7  
Fixed: Shipment ID now uses WooCommerce displayed order number instead of internal order ID.  
Improved: Better compatibility with HPOS and sequential order numbering plugins.  
Enhanced: Shipment reference now matches admin order display for improved consistency.

1.1.6  
Fixed: Expired token issue by implementing automatic token generation and refresh.  
Improved: Removed dependency on manual “Test Connection”.  
Improved: Bulk label creation reliability without prior authentication.  
Enhanced: Token validation to prevent empty token API requests.  
Refactored: Centralized token handling logic across all label operations.  

1.1.5  
Added: Automatic webhook endpoint for real-time tracking updates from DHL.  
Added: Dynamic webhook registration during plugin activation.  
Improved: Automatic update of "Status” in WooCommerce Orders.  
Enhanced: Logging for webhook requests and responses.  
Tested: WooCommerce 9.1.0 & WordPress 6.6  

Added: Company Name field now supports 60 characters.  
Updated: Address Line 1 (60 chars) & Address Line 2 (120 chars) limits.  
Improved: User login redirection to DHL Configuration page.

1.1.4
Fixed: Replaced all error_log() calls with him_dhl_bulk_order_log_msg().  
Improved: Bulk label API requests and responses logging.  
Fixed: Ensured API responses save metadata only after proper validation.  
Improved: Return address fallback logic to prevent invalid API data.  

1.1.3
Fixed: Shipper address handling during bulk label creation.  
Improved: Unified bulk label logging system.  
Fixed: Missing error details in bulk creation logs.  

1.1.2
Improved: Stability and bug fixes.  
Enhanced: Full compatibility with HPOS.  
Added: Support for bulk label ZIP download.  
Updated: Metadata handling for HPOS tables.  
Improved: Session management during label creation.  

1.1.1
Fix: Added messageSource parameter in API requests.

1.1.0
Fix: Weight calculation adjustments.

1.0.9
Fix: Company name is now optional.

1.0.8
Fix: Limited package description to 50 characters.

1.0.7
Fix: Copied shipping details from billing details when only billing exists.  
Fix: Shipping details now populate correctly.

1.0.6
Fix: Conflict with Sequential Order Numbers plugin.

1.0.5
New: Cash on Delivery support improvements.

1.0.4
Fix: Corrected Address Line 1 mapping.

1.0.3
Fix: Populated Remark field with Package Description.  
Fix: Updated tracking URL.

1.0.2
Fix: CSS improvements.

1.0.1
New: Shipper address change implementation.  
New: Error logging for label creation.  
Fix: CSS issues.

1.0.0
Initial release.

**Note:** Before updating the plugin, we strongly recommend backing up your site (files and database) to avoid data loss in case of compatibility issues.