=== Shipping Labels for DHL eCommerce APAC ===
 
Author: Algoleap Technologies Pvt Ltd
Contributors: dhlecommerceasia
Tags: shipping, ecommerce, woocommerce, labels, dhl-shipping
Requires at least: 6.0
Tested up to: 6.6
Stable tag: 1.1.8
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 with WooCommerce. Generate shipping labels, track shipments via Webhooks, and supports HPOS.

== 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.8 ==
 
- **Fixed: Fatal Error on Order Edit Screen (Critical Fix)**
  - Resolved "Call to a member function get_data() on bool" crash occurring on line 108 of the shipping label class.
  - Root cause: `$getOrderproductmname` was a redundant second `wc_get_order()` call that could return `false` (bool) when the order ID variable was undefined, causing a fatal error when `get_data()` was called on it.
  - Fix: Removed the redundant `wc_get_order()` call entirely. The already-resolved `$dhl_order` order object is now reused directly, which is guaranteed valid by the guard above it.
  - `$dhl_order_id` has been restored and is always correctly set from `$dhl_order->get_id()`.
  - The order guard has been strengthened from a loose truthy check (`!$dhl_order`) to a strict type check (`!$dhl_order instanceof WC_Order`), preventing any non-order value from passing through.
 
- **Fixed: Fatal Error on Cash on Delivery Field (Critical Fix)**
  - Resolved "Call to a member function get_total() on null" crash occurring on line 434 of the shipping label class.
  - Root cause: The Cash on Delivery input field in the meta box HTML was still referencing the old `$getOrderproductmname` variable, which no longer exists after the above fix.
  - Fix: Replaced `$getOrderproductmname->get_total()` with `$dhl_order->get_total()`, which is the correct, already-validated order object.
  - All remaining references to `$getOrderproductmname` have been removed from the file — a full scan confirms zero occurrences remain.
 
- **Improved: Order Object Handling**
  - Eliminated all redundant `wc_get_order()` calls inside the meta box render function.
  - Order data, items, and totals are now all retrieved from a single validated `$dhl_order` instance.
  - Reduces database queries per page load on the order edit screen.
 
== 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.8
Fixed: Fatal "Call to a member function get_data() on bool" error on order edit screen (line 108).
Fixed: Fatal "Call to a member function get_total() on null" error on Cash on Delivery field (line 434).
Fixed: Removed all redundant wc_get_order() calls inside meta box render — $dhl_order reused directly.
Fixed: Restored missing $dhl_order_id assignment that was incorrectly commented out.
Improved: Order guard strengthened to instanceof WC_Order check for permanent type safety.
Improved: Reduced database queries on order edit screen by eliminating duplicate order fetches.
 
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.