public function productIdFromItem($WC_Order_Item): int
    {
        // WC 3.0+ uses `\WC_Order_Item_Product` extending `\WC_Order_Item`.
        // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item_Product.html>
        // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html>

        if ($WC_Order_Item instanceof \WC_Order_Item_Product) {
            if (($variation_id = $WC_Order_Item->get_variation_id())) {
                return (int) $variation_id;
            }
            return (int) $WC_Order_Item->get_product_id();
            //
        } elseif ($WC_Order_Item instanceof \WC_Order_Item) {
            return 0; // Not a product item.
            //
        } else { // Back compat.
            $item = (array) $WC_Order_Item;

            if (!empty($item['variation_id'])) {
                return (int) $item['variation_id'];
            }
            return (int) ($item['product_id'] ?? 0);
        }
    }