Order Tracking Debugging

User
Assistant
Thanks for sharing the detailed code. Based on your final note:

> _“for Tracking DHL it only save logs till `Logger::log(' Tracking name custom #dhl' . $tracking_code_title.'-'.$tracking_code);`”_

### Problem
It seems the code **stops execution after this log line** and doesn’t proceed to:
– country check,
– order ID extraction,
– WooCommerce order loading,
– order meta updating,
– order note adding,
– email sending.

### Root Cause
In this block:

if ((isset($order['deliverycountry']) && $order['deliverycountry'] !== 'FR') &&
    (isset($order['invoicecountry']) && $order['invoicecountry'] !== 'FR') &&
    $tracking_code_title != 'Tracking DHL') {
    error_log(print_r('skipped_non_france_order', 1));
    continue;
}

You **only allow non-France orders to pass** *if* `$tracking_code_title == 'Tracking DHL'`.

But look at your condition:

&& $tracking_code_title != 'Tracking DHL'

So when the title *is* `'Tracking DHL'`, **this condition fails**, so the `continue;` is not hit and it should proceed. But **if any of the fields are missing**, execution can still silently break or skip.

### Step-by-Step Fixes & Debug Suggestions

#### ✅ 1. Ensure `deliverycountry` and `invoicecountry` are always set

Add a debug log **just before** the country check:

Logger::log(' Delivery country: ' . ($order['deliverycountry'] ?? 'N/A') . ', Invoice country: ' . ($order['invoicecountry'] ?? 'N/A') . ', Title: ' . $tracking_code_title);

#### ✅ 2. Explicitly handle `Tracking DHL` and allow all countries

Update condition like this:

if (
    $tracking_code_title != 'Tracking DHL' &&
    (
        (isset($order['deliverycountry']) && $order['deliverycountry'] !== 'FR') &&
        (isset($order['invoicecountry']) && $order['invoicecountry'] !== 'FR')
    )
) {
    Logger::log('skipped_non_france_order due to country mismatch');
    continue;
}

Now it will **skip only if it's not DHL and not France**. DHL will always pass.

### 🔄 Next Steps

After making this change:
1. **Enable full logging** after this point (especially for DHL):
– Log order ID extraction
– Log WooCommerce order fetch status

2. **Confirm this line runs** for DHL:

error_log(print_r('wc_order_id: ' . $wc_order_id, 1));

3. **If still not saving DHL tracking info**, check for:
– Tracking title case-sensitivity
– WC order ID mismatch
– Missing `tracking_code` or empty string

Would you like me to rewrite and clean this section fully with the fix?

User
what is !!
Assistant
In PHP, `!!` is a common trick used to **convert any value to a boolean (true or false)**.

### ✅ Explanation:
– `!` is the **logical NOT** operator — it negates the value.
– `!!` applies it **twice**, so it converts the value to a boolean without changing its truthiness.

### 🔍 Example:

$value = 'hello';

$bool = !!$value;

var_dump($bool); // Output: bool(true)

It works like this:
1. `'hello'` is a non-empty string → truthy.
2. `!$value` → `false`
3. `!!$value` → `true`

### 🧠 Use Case:
Useful when you want to **force** a boolean:

function isValid($data) {
    return !!$data; // Ensures true/false, not string/null/array/etc.
}

### 💡 Summary:

| Expression | Result |
|—————-|———|
| `!!'string'` | `true` |
| `!!0` | `false` |
| `!!1` | `true` |
| `!![]` | `true` |
| `!!null` | `false` |

Let me know if you want real-world examples where this is practically helpful.

Leave a Comment

Your email address will not be published. Required fields are marked *