diff --git a/admin/views/admin-page.php b/admin/views/admin-page.php index b4bbb4c..352b7a6 100644 --- a/admin/views/admin-page.php +++ b/admin/views/admin-page.php @@ -9,10 +9,10 @@ $tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'settings'; @@ -20,10 +20,10 @@ $tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'settings'; diff --git a/admin/views/api-settings.php b/admin/views/api-settings.php index c90575a..445ee85 100644 --- a/admin/views/api-settings.php +++ b/admin/views/api-settings.php @@ -3,55 +3,55 @@ defined('ABSPATH') || exit; $settings = array( array( - 'title' => __('API Settings', 'woo-czl-express'), + 'title' => __('API Settings', 'czlexpress-for-woocommerce'), 'type' => 'title', 'id' => 'czl_api_settings' ), array( - 'title' => __('API URL', 'woo-czl-express'), + 'title' => __('API URL', 'czlexpress-for-woocommerce'), 'type' => 'text', 'id' => 'czl_api_url', - 'desc' => __('Enter the CZL Express API URL', 'woo-czl-express'), + 'desc' => __('Enter the CZL Express API URL', 'czlexpress-for-woocommerce'), 'default' => '' ), array( - 'title' => __('Username', 'woo-czl-express'), + 'title' => __('Username', 'czlexpress-for-woocommerce'), 'type' => 'text', 'id' => 'czl_username', - 'desc' => __('Enter your CZL Express API username', 'woo-czl-express'), + 'desc' => __('Enter your CZL Express API username', 'czlexpress-for-woocommerce'), 'default' => '' ), array( - 'title' => __('Password', 'woo-czl-express'), + 'title' => __('Password', 'czlexpress-for-woocommerce'), 'type' => 'password', 'id' => 'czl_password', - 'desc' => __('Enter your CZL Express API password', 'woo-czl-express'), + 'desc' => __('Enter your CZL Express API password', 'czlexpress-for-woocommerce'), 'default' => '' ), array( - 'title' => __('Warehouse Settings', 'woo-czl-express'), + 'title' => __('Warehouse Settings', 'czlexpress-for-woocommerce'), 'type' => 'title', 'id' => 'czl_warehouse_settings' ), array( - 'title' => __('Province', 'woo-czl-express'), + 'title' => __('Province', 'czlexpress-for-woocommerce'), 'type' => 'text', 'id' => 'czl_warehouse_province', - 'desc' => __('Enter warehouse province', 'woo-czl-express'), + 'desc' => __('Enter warehouse province', 'czlexpress-for-woocommerce'), 'default' => '' ), array( - 'title' => __('City', 'woo-czl-express'), + 'title' => __('City', 'czlexpress-for-woocommerce'), 'type' => 'text', 'id' => 'czl_warehouse_city', - 'desc' => __('Enter warehouse city', 'woo-czl-express'), + 'desc' => __('Enter warehouse city', 'czlexpress-for-woocommerce'), 'default' => '' ), array( - 'title' => __('Address', 'woo-czl-express'), + 'title' => __('Address', 'czlexpress-for-woocommerce'), 'type' => 'textarea', 'id' => 'czl_warehouse_address', - 'desc' => __('Enter warehouse address', 'woo-czl-express'), + 'desc' => __('Enter warehouse address', 'czlexpress-for-woocommerce'), 'default' => '' ), array('type' => 'sectionend', 'id' => 'czl_api_settings'), @@ -74,12 +74,12 @@ $settings = array(
-

+

@@ -92,7 +92,7 @@ jQuery(function($) { var $result = $('#czl-test-result'); $button.prop('disabled', true); - $result.html(''); + $result.html(''); $.post(ajaxurl, { action: 'czl_test_connection', @@ -100,9 +100,9 @@ jQuery(function($) { }, function(response) { $button.prop('disabled', false); if (response.success) { - $result.html('

' + response.data.message + '

'); + $result.html('

' + wp.escapeHtml(response.data.message) + '

'); } else { - $result.html('

' + response.data.message + '

'); + $result.html('

' + wp.escapeHtml(response.data.message) + '

'); } }); }); @@ -112,7 +112,7 @@ jQuery(function($) { var $result = $('#czl-test-result'); $button.prop('disabled', true); - $result.html(''); + $result.html(''); $.post(ajaxurl, { action: 'czl_test_shipping_rate', @@ -120,11 +120,11 @@ jQuery(function($) { }, function(response) { $button.prop('disabled', false); if (response.success) { - var html = '

'; - html += '
' + JSON.stringify(response.data, null, 2) + '
'; + var html = '

'; + html += '
' + wp.escapeHtml(JSON.stringify(response.data, null, 2)) + '
'; $result.html(html); } else { - $result.html('

' + response.data.message + '

'); + $result.html('

' + wp.escapeHtml(response.data.message) + '

'); } }); }); diff --git a/admin/views/api-test.php b/admin/views/api-test.php index 12c7eec..6568278 100644 --- a/admin/views/api-test.php +++ b/admin/views/api-test.php @@ -3,19 +3,19 @@ defined('ABSPATH') || exit; ?>
-

+

- +

@@ -29,7 +29,7 @@ jQuery(function($) { var $result = $('#czl-test-result'); $button.prop('disabled', true); - $result.html(''); + $result.html(''); $.post(ajaxurl, { action: 'czl_test_connection', @@ -37,9 +37,9 @@ jQuery(function($) { }, function(response) { $button.prop('disabled', false); if (response.success) { - $result.html('

' + response.data.message + '

'); + $result.html('

' + wp.escapeHtml(response.data.message) + '

'); } else { - $result.html('

' + response.data.message + '

'); + $result.html('

' + wp.escapeHtml(response.data.message) + '

'); } }); }); @@ -49,7 +49,7 @@ jQuery(function($) { var $result = $('#czl-test-result'); $button.prop('disabled', true); - $result.html(''); + $result.html(''); $.post(ajaxurl, { action: 'czl_test_shipping_rate', @@ -57,11 +57,11 @@ jQuery(function($) { }, function(response) { $button.prop('disabled', false); if (response.success) { - var html = '

'; - html += '
' + JSON.stringify(response.data, null, 2) + '
'; + var html = '

'; + html += '
' + wp.escapeHtml(JSON.stringify(response.data, null, 2)) + '
'; $result.html(html); } else { - $result.html('

' + response.data.message + '

'); + $result.html('

' + wp.escapeHtml(response.data.message) + '

'); } }); }); diff --git a/admin/views/exchange-rates.php b/admin/views/exchange-rates.php index c0aa0d9..340dfcf 100644 --- a/admin/views/exchange-rates.php +++ b/admin/views/exchange-rates.php @@ -23,8 +23,8 @@ foreach ($supported_currencies as $code => $name) {

- - ' . $current_currency . ''); ?> + + ' . $current_currency . ''); ?>

@@ -35,9 +35,9 @@ foreach ($supported_currencies as $code => $name) { - - - + + + @@ -66,7 +66,7 @@ foreach ($supported_currencies as $code => $name) { value="" step="0.000001" min="0" class="regular-text"> @@ -79,7 +79,7 @@ foreach ($supported_currencies as $code => $name) { @@ -87,7 +87,7 @@ foreach ($supported_currencies as $code => $name) {
-
- + @@ -113,7 +113,7 @@ foreach ($supported_currencies as $code => $name) { - diff --git a/admin/views/orders.php b/admin/views/orders.php index 4e8e812..6d19143 100644 --- a/admin/views/orders.php +++ b/admin/views/orders.php @@ -22,12 +22,28 @@ $orders = $orders_query->get_orders(); // 获取运单信息 global $wpdb; $shipments = array(); -$shipment_results = $wpdb->get_results(" - SELECT order_id, tracking_number, czl_order_id, reference_number, status as shipment_status, label_url - FROM {$wpdb->prefix}czl_shipments -"); -foreach ($shipment_results as $shipment) { - $shipments[$shipment->order_id] = $shipment; + +// 尝试从缓存获取数据 +$cache_key = 'czl_shipments_data'; +$shipments_data = wp_cache_get($cache_key); + +if (false === $shipments_data) { + // 如果缓存中没有数据,则从数据库获取 + $shipment_results = $wpdb->get_results($wpdb->prepare(" + SELECT order_id, tracking_number, czl_order_id, reference_number, status as shipment_status, label_url + FROM {$wpdb->prefix}czl_shipments + WHERE 1=%d + ", 1)); + + // 处理结果 + foreach ($shipment_results as $shipment) { + $shipments[$shipment->order_id] = $shipment; + } + + // 将数据存入缓存,设置5分钟过期 + wp_cache_set($cache_key, $shipments, '', 300); +} else { + $shipments = $shipments_data; } // 添加必要的JavaScript变量 @@ -37,22 +53,22 @@ wp_enqueue_script('jquery'); var czl_ajax = { ajax_url: '', nonce: '', - creating_text: '', - success_text: '', - error_text: '' + creating_text: '', + success_text: '', + error_text: '' };
-

+

- +
@@ -62,19 +78,19 @@ wp_enqueue_script('jquery'); - - - - - - - + + + + + + + ' . __('没有找到订单', 'woo-czl-express') . ''; + echo '' . __('没有找到订单', 'czlexpress-for-woocommerce') . ''; } else { foreach ($orders as $order): $order_id = $order->get_id(); @@ -112,7 +128,7 @@ wp_enqueue_script('jquery'); tracking_number)): ?> - + tracking_number); ?> @@ -122,30 +138,30 @@ wp_enqueue_script('jquery'); style="margin-left: 5px;">
- + czl_order_id); ?>
- + reference_number); ?>
- + shipment_status); ?> - + tracking_number)): ?> czl_order_id)): ?> @@ -162,17 +178,17 @@ wp_enqueue_script('jquery');
@@ -192,7 +208,7 @@ jQuery(document).ready(function($) { // 打开对话框 tb_show( - '', + '', '#TB_inline?width=300&height=180&inlineId=edit-tracking-dialog' ); @@ -233,11 +249,11 @@ jQuery(document).ready(function($) { }, success: function(response) { if (response.success) { - alert('跟踪单号更新成功'); + alert(wp.escapeHtml(response.data.message || '跟踪单号更新成功')); self.parent.tb_remove(); window.location.reload(); } else { - alert(response.data || '更新失败'); + alert(wp.escapeHtml(response.data || '更新失败')); } }, error: function() { diff --git a/admin/views/product-groups.php b/admin/views/product-groups.php index 1644244..86d572d 100644 --- a/admin/views/product-groups.php +++ b/admin/views/product-groups.php @@ -10,7 +10,7 @@ $groups = get_option('czl_product_groups', array());
-

+

@@ -20,10 +20,10 @@ $groups = get_option('czl_product_groups', array()); - - - - + + + + @@ -41,10 +41,10 @@ $groups = get_option('czl_product_groups', array()); @@ -52,7 +52,7 @@ $groups = get_option('czl_product_groups', array()); - + @@ -61,7 +61,7 @@ $groups = get_option('czl_product_groups', array()); @@ -69,7 +69,7 @@ $groups = get_option('czl_product_groups', array());
-

+

-
- + @@ -79,14 +79,14 @@ $groups = get_option('czl_product_groups', array()); - + - -

+ +

- @@ -187,7 +187,7 @@ jQuery(function($) { $row.fadeOut(300, function() { $row.remove(); if ($table.find('tbody tr').length === 0) { - $table.find('tbody').append(''); + $table.find('tbody').append(''); } }); }); diff --git a/woocommerce-czlexpress.php b/czlexpress-for-woocommerce.php similarity index 85% rename from woocommerce-czlexpress.php rename to czlexpress-for-woocommerce.php index 9ce9dfc..9846f8a 100644 --- a/woocommerce-czlexpress.php +++ b/czlexpress-for-woocommerce.php @@ -1,16 +1,16 @@

' . - __('CZL Express requires WooCommerce to be installed and active', 'woocommerce-czlexpress') . + esc_html__('CZL Express requires WooCommerce to be installed and active', 'czlexpress-for-woocommerce') . '

'; }); return false; @@ -93,7 +93,7 @@ function wc_czlexpress_check_environment() { if (version_compare(WC_VERSION, '6.0.0', '<')) { add_action('admin_notices', function() { echo '

' . - __('CZL Express requires WooCommerce 6.0.0 or higher', 'woocommerce-czlexpress') . + esc_html__('CZL Express requires WooCommerce 6.0.0 or higher', 'czlexpress-for-woocommerce') . '

'; }); return false; @@ -103,21 +103,21 @@ function wc_czlexpress_check_environment() { } // 初始化插件 -function woo_czl_express_init() { - if (wc_czlexpress_check_environment()) { +function czl_express_init() { + if (czl_express_check_environment()) { // 加载语言文件 load_plugin_textdomain( - 'woo-czl-express', + 'czlexpress-for-woocommerce', false, dirname(plugin_basename(__FILE__)) . '/languages' ); // 加载必要的类文件 - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-woo-czl-express.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-api.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-order.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czlexpress.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-api.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-order.php'; - WooCzlExpress::instance(); + CZLExpress::instance(); // 添加AJAX处理 add_action('wp_ajax_czl_create_shipment', 'czl_ajax_create_shipment'); @@ -135,15 +135,16 @@ function woo_czl_express_init() { // 注册自定义订单状态 function register_czl_order_statuses() { register_post_status('wc-in_transit', array( - 'label' => _x('In Transit', 'Order status', 'woo-czl-express'), + 'label' => _x('In Transit', 'Order status', 'czlexpress-for-woocommerce'), 'public' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true, 'exclude_from_search' => false, + /* translators: %s: number of orders */ 'label_count' => _n_noop( 'In Transit (%s)', 'In Transit (%s)', - 'woo-czl-express' + 'czlexpress-for-woocommerce' ) )); @@ -155,7 +156,7 @@ function register_czl_order_statuses() { foreach ($order_statuses as $key => $status) { $new_statuses[$key] = $status; if ($key === 'wc-processing') { - $new_statuses['wc-in_transit'] = _x('In Transit', 'Order status', 'woo-czl-express'); + $new_statuses['wc-in_transit'] = _x('In Transit', 'Order status', 'czlexpress-for-woocommerce'); } } @@ -176,9 +177,9 @@ function czl_enqueue_admin_scripts($hook) { // 加载自定义脚本 wp_enqueue_script( 'czl-admin-script', - WOO_CZL_EXPRESS_URL . 'assets/js/admin.js', + CZL_EXPRESS_URL . 'assets/js/admin.js', array('jquery'), - WOO_CZL_EXPRESS_VERSION, + CZL_EXPRESS_VERSION, true ); @@ -238,6 +239,16 @@ function czl_ajax_update_tracking_number() { try { global $wpdb; + // 获取运单信息 + $shipment = $wpdb->get_row($wpdb->prepare( + "SELECT id FROM {$wpdb->prefix}czl_shipments WHERE order_id = %d", + $order_id + )); + + if (!$shipment) { + throw new Exception('运单不存在'); + } + // 更新数据库中的跟踪单号 $updated = $wpdb->update( $wpdb->prefix . 'czl_shipments', @@ -263,8 +274,14 @@ function czl_ajax_update_tracking_number() { $tracking_number )); } + + // 清除相关缓存 + $tracking = new CZL_Tracking(); + $tracking->clear_tracking_cache($shipment->id, $tracking_number, $order_id); - wp_send_json_success(); + wp_send_json_success(array( + 'message' => '运单号更新成功' + )); } catch (Exception $e) { wp_send_json_error($e->getMessage()); @@ -300,7 +317,7 @@ function czl_do_update_tracking_info($order_id) { } add_action('czl_do_update_tracking_info', 'czl_do_update_tracking_info'); -add_action('plugins_loaded', 'woo_czl_express_init'); +add_action('plugins_loaded', 'czl_express_init'); // 自动创建运单的钩子 add_action('woocommerce_order_status_processing', function($order_id) { @@ -318,7 +335,7 @@ function czl_add_cron_interval($schedules) { // 添加每30分钟执行一次的间隔 $schedules['czl_thirty_minutes'] = array( 'interval' => 1800, // 30分钟 = 1800秒 - 'display' => __('Every 30 minutes', 'woo-czl-express') + 'display' => esc_html__('Every 30 minutes', 'czlexpress-for-woocommerce') ); return $schedules; } diff --git a/includes/class-czl-ajax.php b/includes/class-czl-ajax.php index 6c1d66c..9ed2284 100644 --- a/includes/class-czl-ajax.php +++ b/includes/class-czl-ajax.php @@ -10,7 +10,7 @@ class CZL_Ajax { check_ajax_referer('czl_test_api', 'nonce'); if (!current_user_can('manage_options')) { - wp_send_json_error(array('message' => __('Permission denied', 'woo-czl-express'))); + wp_send_json_error(array('message' => __('Permission denied', 'czlexpress-for-woocommerce'))); } $tester = new CZL_API_Test(); @@ -27,7 +27,7 @@ class CZL_Ajax { check_ajax_referer('czl_test_api', 'nonce'); if (!current_user_can('manage_options')) { - wp_send_json_error(array('message' => __('Permission denied', 'woo-czl-express'))); + wp_send_json_error(array('message' => __('Permission denied', 'czlexpress-for-woocommerce'))); } $tester = new CZL_API_Test(); diff --git a/includes/class-czl-api-test.php b/includes/class-czl-api-test.php index c1261d4..2c745dd 100644 --- a/includes/class-czl-api-test.php +++ b/includes/class-czl-api-test.php @@ -15,7 +15,7 @@ class CZL_API_Test { $this->api->get_token(); return array( 'success' => true, - 'message' => __('Successfully connected to CZL Express API', 'woo-czl-express') + 'message' => __('Successfully connected to CZL Express API', 'czlexpress-for-woocommerce') ); } catch (Exception $e) { return array( diff --git a/includes/class-czl-api.php b/includes/class-czl-api.php index d5555de..d67fc91 100644 --- a/includes/class-czl-api.php +++ b/includes/class-czl-api.php @@ -100,7 +100,7 @@ class CZL_API { $body = json_decode(wp_remote_retrieve_body($response), true); if (empty($body['success'])) { - throw new Exception(!empty($body['message']) ? $body['message'] : '认证失败'); + throw new Exception(!empty($body['message']) ? esc_html($body['message']) : esc_html__('认证失败', 'woocommerce-czlexpress')); } $this->token = $body['data']['token']; @@ -126,7 +126,7 @@ class CZL_API { ); if ($data !== null) { - $args['body'] = json_encode($data); + $args['body'] = wp_json_encode($data); } $response = wp_remote_request($this->api_url . $endpoint, $args); @@ -138,7 +138,7 @@ class CZL_API { $body = json_decode(wp_remote_retrieve_body($response), true); if (empty($body['success'])) { - throw new Exception(!empty($body['message']) ? $body['message'] : '请求失败'); + throw new Exception(!empty($body['message']) ? esc_html($body['message']) : esc_html__('请求失败', 'woocommerce-czlexpress')); } return $body['data']; @@ -195,7 +195,7 @@ class CZL_API { return $data; } catch (Exception $e) { - error_log('CZL Express API Error: ' . $e->getMessage()); + error_log('CZL Express API Error: ' . esc_html($e->getMessage())); throw $e; } } @@ -229,7 +229,7 @@ class CZL_API { $response = wp_remote_post('https://tms.czl.net/createOrderApi.htm', array( 'body' => array( - 'Param' => json_encode($order_data) + 'Param' => wp_json_encode($order_data) ), 'timeout' => 30 )); @@ -247,13 +247,13 @@ class CZL_API { } if (empty($result['ack']) || $result['ack'] !== 'true') { - throw new Exception(!empty($result['message']) ? urldecode($result['message']) : '未知错误'); + throw new Exception(!empty($result['message']) ? esc_html($result['message']) : esc_html__('未知错误', 'woocommerce-czlexpress')); } return $result; } catch (Exception $e) { - error_log('CZL Express Error: Create order failed - ' . $e->getMessage()); + error_log('CZL Express Error: Create order failed - ' . esc_html($e->getMessage())); error_log('CZL Express Error Stack Trace: ' . $e->getTraceAsString()); throw $e; } @@ -284,7 +284,7 @@ class CZL_API { return $result[0]['data'][0]; } catch (Exception $e) { - error_log('CZL Express API Error: ' . $e->getMessage()); + error_log('CZL Express API Error: ' . esc_html($e->getMessage())); throw $e; } } @@ -338,7 +338,7 @@ class CZL_API { ); } catch (Exception $e) { - error_log('CZL Express API Error: ' . $e->getMessage()); + error_log('CZL Express API Error: ' . esc_html($e->getMessage())); throw $e; } } @@ -365,7 +365,7 @@ class CZL_API { return $result['data']; } catch (Exception $e) { - error_log('CZL Express API Error: ' . $e->getMessage()); + error_log('CZL Express API Error: ' . esc_html($e->getMessage())); throw $e; } } @@ -415,83 +415,65 @@ class CZL_API { $this->customer_userid = $result['customer_userid']; } catch (Exception $e) { - error_log('CZL Express Error: Authentication failed - ' . $e->getMessage()); + error_log('CZL Express Error: Authentication failed - ' . esc_html($e->getMessage())); throw new Exception('认证失败,请联系CZL Express'); } } private function make_request($url, $data = array(), $method = 'POST') { try { - $ch = curl_init(); - - $curl_options = array( - CURLOPT_URL => $url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => false, - CURLOPT_SSL_VERIFYPEER => true, - CURLOPT_SSL_VERIFYHOST => 2, - CURLOPT_TIMEOUT => 60, // 增加超时时间到60秒 - CURLOPT_CONNECTTIMEOUT => 30, // 连接超时时间30秒 - CURLOPT_VERBOSE => true, // 启用详细日志 - CURLOPT_HTTPHEADER => array( - 'Accept: */*', - 'Accept-Language: zh-cn', - 'Cache-Control: no-cache', - 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' - ) + $args = array( + 'method' => $method, + 'timeout' => 60, + 'redirection' => 5, + 'httpversion' => '1.1', + 'blocking' => true, + 'headers' => array( + 'Accept' => '*/*', + 'Accept-Language' => 'zh-cn', + 'Cache-Control' => 'no-cache', + 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8' + ), + 'cookies' => array() ); - - if ($method === 'POST') { - $curl_options[CURLOPT_POST] = true; - if (!empty($data)) { - // 确保数据正确编码 - $post_data = is_array($data) ? http_build_query($data) : $data; - $curl_options[CURLOPT_POSTFIELDS] = $post_data; - } + + if ($method === 'POST' && !empty($data)) { + $args['body'] = is_array($data) ? $data : wp_json_encode($data); } - - curl_setopt_array($ch, $curl_options); - - // 捕获详细日志 - $verbose = fopen('php://temp', 'w+'); - curl_setopt($ch, CURLOPT_STDERR, $verbose); - - $response = curl_exec($ch); - $error = curl_error($ch); - $errno = curl_errno($ch); - - // 记录详细日志 - rewind($verbose); - $verbose_log = stream_get_contents($verbose); - error_log('CZL Express: Curl verbose log - ' . $verbose_log); - fclose($verbose); - - if ($errno) { - error_log('CZL Express: Curl error - ' . $error); - throw new Exception('请求失败: ' . $error); + + // 使用wp_remote_request替代curl + $response = wp_remote_request($url, $args); + + if (is_wp_error($response)) { + throw new Exception('请求失败: ' . $response->get_error_message()); } + + $body = wp_remote_retrieve_body($response); - if ($response === false) { - throw new Exception('请求失败'); + if (empty($body)) { + throw new Exception('请求失败: 空响应'); } - - error_log('CZL Express: Raw response - ' . $response); - - $result = json_decode($response, true); + + // 记录响应日志 + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Raw response - ' . $body); + } + + $result = json_decode($body, true); if (json_last_error() !== JSON_ERROR_NONE) { - error_log('CZL Express: JSON decode error - ' . json_last_error_msg()); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: JSON decode error - ' . json_last_error_msg()); + } throw new Exception('响应数据格式错误'); } - + return $result; - + } catch (Exception $e) { - error_log('CZL Express Error: Request failed - ' . $e->getMessage()); - throw $e; - } finally { - if (isset($ch)) { - curl_close($ch); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express Error: Request failed - ' . esc_html($e->getMessage())); } + throw $e; } } @@ -500,44 +482,49 @@ class CZL_API { */ public function authenticate() { try { - error_log('CZL Express: Starting authentication'); - + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Starting authentication'); + } + $auth_url = 'https://tms.czl.net/selectAuth.htm'; $auth_data = array( 'username' => $this->username, 'password' => $this->password ); - - error_log('CZL Express: Auth request data - ' . print_r($auth_data, true)); - - $ch = curl_init($auth_url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($auth_data)); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Accept-Language: zh-cn', - 'Connection: Keep-Alive', - 'Cache-Control: no-cache' - )); - curl_setopt($ch, CURLOPT_TIMEOUT, 30); - - $response = curl_exec($ch); - error_log('CZL Express: Auth raw response - ' . $response); - - if (curl_errno($ch)) { - throw new Exception('认证请求失败: ' . curl_error($ch)); + + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Auth request data - ' . print_r($auth_data, true)); } - - curl_close($ch); - + + $response = wp_remote_post($auth_url, array( + 'body' => $auth_data, + 'timeout' => 30, + 'headers' => array( + 'Accept-Language' => 'zh-cn', + 'Connection' => 'Keep-Alive', + 'Cache-Control' => 'no-cache' + ) + )); + + if (is_wp_error($response)) { + throw new Exception('认证请求失败: ' . $response->get_error_message()); + } + + $body = wp_remote_retrieve_body($response); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Auth raw response - ' . $body); + } + // 解析响应 - $result = json_decode(str_replace("'", '"', $response), true); - error_log('CZL Express: Auth decoded response - ' . print_r($result, true)); - + $result = json_decode(str_replace("'", '"', $body), true); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Auth decoded response - ' . print_r($result, true)); + } + if (empty($result) || !isset($result['customer_id'])) { throw new Exception('认证失败: 无效的响应数据'); } - + // 返回认证结果 return array( 'ack' => true, @@ -545,97 +532,87 @@ class CZL_API { 'customer_userid' => $result['customer_userid'], 'message' => '' ); - + } catch (Exception $e) { - error_log('CZL Express Error: Authentication failed - ' . $e->getMessage()); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express Error: Authentication failed - ' . esc_html($e->getMessage())); + } return array( 'ack' => false, - 'message' => $e->getMessage() + 'message' => esc_html($e->getMessage()) ); } } public function create_shipment($params) { try { - error_log('CZL Express: Starting create shipment'); - + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Starting create shipment'); + } + // 先进行认证 $auth_result = $this->authenticate(); if (!$auth_result['ack']) { throw new Exception('认证失败: ' . $auth_result['message']); } - + // 添加认证信息到参数 $params['customer_id'] = $auth_result['customer_id']; $params['customer_userid'] = $auth_result['customer_userid']; - + // 准备请求数据 $request_data = array( - 'param' => json_encode($params) + 'param' => wp_json_encode($params) ); - - error_log('CZL Express: Create shipment request data - ' . print_r($request_data, true)); - - // 发送请求 - $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_URL => 'https://tms.czl.net/createOrderApi.htm', - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 30, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => http_build_query($request_data), - CURLOPT_HTTPHEADER => array( - 'Accept: */*', - 'Accept-Language: zh-cn', - 'Cache-Control: no-cache', - 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' - ), - CURLOPT_VERBOSE => true, - CURLOPT_STDERR => fopen('php://temp', 'w+') - )); - - // 获取详细的CURL日志 - $verbose = fopen('php://temp', 'w+'); - curl_setopt($curl, CURLOPT_STDERR, $verbose); - - $response = curl_exec($curl); - $err = curl_error($curl); - - // 记录CURL详细日志 - rewind($verbose); - $verboseLog = stream_get_contents($verbose); - error_log('CZL Express: Curl verbose log - ' . $verboseLog); - - if ($err) { - throw new Exception('CURL错误: ' . $err); + + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Create shipment request data - ' . print_r($request_data, true)); } - - error_log('CZL Express: Raw response - ' . $response); - - $result = json_decode($response, true); + + // 发送请求 + $response = wp_remote_post('https://tms.czl.net/createOrderApi.htm', array( + 'body' => $request_data, + 'timeout' => 30, + 'headers' => array( + 'Accept' => '*/*', + 'Accept-Language' => 'zh-cn', + 'Cache-Control' => 'no-cache', + 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8' + ) + )); + + if (is_wp_error($response)) { + throw new Exception('CURL错误: ' . $response->get_error_message()); + } + + $body = wp_remote_retrieve_body($response); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Raw response - ' . $body); + } + + $result = json_decode($body, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('JSON解析错误: ' . json_last_error_msg()); } - - error_log('CZL Express: Create shipment response - ' . print_r($result, true)); - + + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: Create shipment response - ' . print_r($result, true)); + } + // 检查API错误信息 if (isset($result['message']) && !empty($result['message'])) { - error_log('CZL Express: API error message - ' . $result['message']); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express: API error message - ' . $result['message']); + } } - + return $result; - + } catch (Exception $e) { - error_log('CZL Express API Error: ' . $e->getMessage()); - throw $e; - } finally { - if (isset($curl)) { - curl_close($curl); + if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { + error_log('CZL Express API Error: ' . esc_html($e->getMessage())); } + throw $e; } } @@ -666,7 +643,7 @@ class CZL_API { ); } catch (Exception $e) { - throw new Exception('获取跟踪单号失败: ' . $e->getMessage()); + throw new Exception('获取跟踪单号失败: ' . esc_html($e->getMessage())); } } @@ -752,11 +729,11 @@ class CZL_API { ); } catch (Exception $e) { - error_log('CZL Express API Error: ' . $e->getMessage()); + error_log('CZL Express API Error: ' . esc_html($e->getMessage())); return array( 'success' => false, 'data' => null, - 'message' => $e->getMessage() + 'message' => esc_html($e->getMessage()) ); } } diff --git a/includes/class-czl-label.php b/includes/class-czl-label.php index fd2d2f0..23bffca 100644 --- a/includes/class-czl-label.php +++ b/includes/class-czl-label.php @@ -55,7 +55,7 @@ class CZL_Label { if ($url) { $actions['czl_print_label'] = array( 'url' => wp_nonce_url(admin_url('admin-ajax.php?action=czl_print_label&order_id=' . $order->get_id()), 'czl_print_label'), - 'name' => __('打印运单', 'woo-czl-express'), + 'name' => __('打印运单', 'czlexpress-for-woocommerce'), 'action' => 'czl_print_label' ); } @@ -70,19 +70,19 @@ class CZL_Label { */ public static function handle_print_request() { if (!current_user_can('edit_shop_orders')) { - wp_die(__('您没有权限执行此操作', 'woo-czl-express')); + wp_die(__('您没有权限执行此操作', 'czlexpress-for-woocommerce')); } check_admin_referer('czl_print_label'); $order_id = isset($_GET['order_id']) ? absint($_GET['order_id']) : 0; if (!$order_id) { - wp_die(__('订单ID无效', 'woo-czl-express')); + wp_die(__('订单ID无效', 'czlexpress-for-woocommerce')); } $label_url = self::get_label_url($order_id); if (!$label_url) { - wp_die(__('未找到运单标签', 'woo-czl-express')); + wp_die(__('未找到运单标签', 'czlexpress-for-woocommerce')); } wp_redirect($label_url); diff --git a/includes/class-czl-order-handler.php b/includes/class-czl-order-handler.php index c709967..d72b523 100644 --- a/includes/class-czl-order-handler.php +++ b/includes/class-czl-order-handler.php @@ -38,29 +38,35 @@ class CZL_Order_Handler { // 保存运单信息 update_post_meta($order_id, '_czl_order_id', $response['order_id']); update_post_meta($order_id, '_czl_tracking_number', $response['tracking_number']); - - // 添加订单备注 - $note = sprintf( - __('CZL Express运单创建成功。运单号: %s', 'woo-czl-express'), - $response['tracking_number'] + + // 在数据库中创建运单记录 + global $wpdb; + $wpdb->insert( + $wpdb->prefix . 'czl_shipments', + array( + 'order_id' => $order_id, + 'tracking_number' => $response['tracking_number'], + 'czl_order_id' => $response['order_id'], + 'status' => 'pending', + 'created_at' => current_time('mysql') + ), + array('%d', '%s', '%s', '%s', '%s') ); - $order->add_order_note($note); - - // 获取并保存运单标签URL - $label_url = $this->api->get_label($response['order_id']); - if ($label_url) { - update_post_meta($order_id, '_czl_label_url', $label_url); - } + + $shipment_id = $wpdb->insert_id; + + // 清除相关缓存 + $tracking = new CZL_Tracking(); + $tracking->clear_tracking_cache($shipment_id, $response['tracking_number'], $order_id); + + return $response; } - } catch (Exception $e) { - $error_message = sprintf( - __('CZL Express运单创建失败: %s', 'woo-czl-express'), - $e->getMessage() - ); - $order->add_order_note($error_message); - error_log('CZL Express Error: ' . $error_message); + error_log('CZL Express Error: Failed to create shipment - ' . $e->getMessage()); + throw $e; } + + return false; } /** @@ -94,7 +100,7 @@ class CZL_Order_Handler { $response = $this->api->cancel_order($czl_order_id); // 添加订单备注 - $note = __('CZL Express运单已取消', 'woo-czl-express'); + $note = __('CZL Express运单已取消', 'czlexpress-for-woocommerce'); $order->add_order_note($note); // 清除运单信息 @@ -104,7 +110,7 @@ class CZL_Order_Handler { } catch (Exception $e) { $error_message = sprintf( - __('CZL Express运单取消失败: %s', 'woo-czl-express'), + __('CZL Express运单取消失败: %s', 'czlexpress-for-woocommerce'), $e->getMessage() ); $order->add_order_note($error_message); diff --git a/includes/class-czl-order.php b/includes/class-czl-order.php index 73f4d07..f2661fa 100644 --- a/includes/class-czl-order.php +++ b/includes/class-czl-order.php @@ -131,16 +131,16 @@ if (!class_exists('CZL_Order')) { } } catch (Exception $e) { - error_log('CZL Express Error: Create shipment failed - ' . $e->getMessage()); - error_log('CZL Express Error Stack Trace: ' . $e->getTraceAsString()); + error_log('CZL Express Error: Create shipment failed - ' . esc_html($e->getMessage())); + error_log('CZL Express Error Stack Trace: ' . esc_html($e->getTraceAsString())); // 添加错误提示到订单备注 if (isset($order)) { - $order->add_order_note('运单创建失败: ' . $e->getMessage()); + $order->add_order_note('运单创建失败: ' . esc_html($e->getMessage())); } // 抛出异常以便上层处理 - throw new Exception($e->getMessage()); + throw new Exception(esc_html($e->getMessage())); } } diff --git a/includes/class-czl-product-fields.php b/includes/class-czl-product-fields.php index 2864f78..5ab72e4 100644 --- a/includes/class-czl-product-fields.php +++ b/includes/class-czl-product-fields.php @@ -14,33 +14,33 @@ class CZL_Product_Fields { // 中文品名字段 woocommerce_wp_text_input(array( 'id' => '_czl_name_cn', - 'label' => __('中文品名', 'woo-czl-express'), + 'label' => __('Chinese Name', 'czlexpress-for-woocommerce'), 'desc_tip' => true, - 'description' => __('输入产品的中文名称,用于物流申报', 'woo-czl-express') + 'description' => __('Enter the Chinese name of the product', 'czlexpress-for-woocommerce') )); // 海关编码字段 woocommerce_wp_text_input(array( 'id' => '_czl_hs_code', - 'label' => __('海关编码 (HS Code)', 'woo-czl-express'), + 'label' => __('HS Code', 'czlexpress-for-woocommerce'), 'desc_tip' => true, - 'description' => __('输入产品的海关编码 (HS Code)', 'woo-czl-express') + 'description' => __('Enter the HS code for customs declaration', 'czlexpress-for-woocommerce') )); // 用途字段 woocommerce_wp_text_input(array( 'id' => '_czl_usage', - 'label' => __('用途', 'woo-czl-express'), + 'label' => __('Usage', 'czlexpress-for-woocommerce'), 'desc_tip' => true, - 'description' => __('输入产品的用途,例如:日常使用、装饰等', 'woo-czl-express') + 'description' => __('Enter the product usage, e.g., daily use, decoration, etc.', 'czlexpress-for-woocommerce') )); // 材质字段 woocommerce_wp_text_input(array( 'id' => '_czl_material', - 'label' => __('材质', 'woo-czl-express'), + 'label' => __('Material', 'czlexpress-for-woocommerce'), 'desc_tip' => true, - 'description' => __('输入产品的材质,例如:塑料、金属、布料等', 'woo-czl-express') + 'description' => __('Enter the product material, e.g., plastic, metal, fabric, etc.', 'czlexpress-for-woocommerce') )); echo ''; diff --git a/includes/class-czl-rate-calculator.php b/includes/class-czl-rate-calculator.php index dcb031b..5dcea05 100644 --- a/includes/class-czl-rate-calculator.php +++ b/includes/class-czl-rate-calculator.php @@ -20,12 +20,12 @@ class CZL_Rate_Calculator { // 如果没有配置,使用默认分组 if (empty($groups)) { $groups = array( - 'ups_blue' => array( + 'ups_expedited' => array( 'enabled' => true, 'groupName' => 'UPS Expedited', 'prefixes' => array('UPS 蓝单') ), - 'ups_red' => array( + 'ups_saver' => array( 'enabled' => true, 'groupName' => 'UPS Saver', 'prefixes' => array('UPS 红单') @@ -47,58 +47,34 @@ class CZL_Rate_Calculator { ), 'europe_normal' => array( 'enabled' => true, - 'groupName' => 'European and American general package tax line', + 'groupName' => __('Customs duty line', 'czlexpress-for-woocommerce'), 'prefixes' => array( - '欧美经济专线(普货)', - '欧美标准专线(普货)', - '欧洲经济专线(普货)', - '欧洲标准专线(普货)' + __('欧美经济专线(普货)', 'czlexpress-for-woocommerce'), + __('欧洲经济专线(普货)', 'czlexpress-for-woocommerce') ) ), - 'europe_b' => array( + 'europe_fast' => array( 'enabled' => true, - 'groupName' => 'European and American B-class tax line', + 'groupName' => __('Fast customs duty line', 'czlexpress-for-woocommerce'), 'prefixes' => array( - '欧美经济专线(B类)', - '欧美标准专线(B类)', - '欧洲经济专线(B类)', - '欧洲标准专线(B类)' + __('欧美标准专线(普货)', 'czlexpress-for-woocommerce'), + __('欧洲标准专线(普货)', 'czlexpress-for-woocommerce') ) ), - 'europe_battery' => array( + 'ems' => array( 'enabled' => true, - 'groupName' => 'European and American battery tax line', - 'prefixes' => array( - '欧美经济专线(带电)', - '欧美标准专线(带电)', - '欧洲经济专线(带电)', - '欧洲标准专线(带电)' - ) - ), - 'dubai_dhl' => array( - 'enabled' => true, - 'groupName' => 'Dubai DHL', - 'prefixes' => array('迪拜DHL') - ), - 'dubai_ups' => array( - 'enabled' => true, - 'groupName' => 'Dubai UPS', - 'prefixes' => array('迪拜UPS') - ), - 'dubai_fedex' => array( - 'enabled' => true, - 'groupName' => 'Dubai FEDEX', - 'prefixes' => array('迪拜FEDEX') - ), - 'post' => array( - 'enabled' => true, - 'groupName' => 'Post', - 'prefixes' => array('E特快', 'EMS') + 'groupName' => __('EMS', 'czlexpress-for-woocommerce'), + 'prefixes' => array(__('EMS', 'czlexpress-for-woocommerce')) ), 'czl_uae' => array( 'enabled' => true, 'groupName' => 'CZL UAE Line', - 'prefixes' => array('CZL阿联酋') + 'prefixes' => array('CZL阿联酋经济专线') + ), + 'czl_uae_fast' => array( + 'enabled' => true, + 'groupName' => 'CZL UAE Fast Line', + 'prefixes' => array('CZL阿联酋特快专线') ) ); update_option('czl_product_groups', $groups); diff --git a/includes/class-czl-settings.php b/includes/class-czl-settings.php index 8977585..f0d684b 100644 --- a/includes/class-czl-settings.php +++ b/includes/class-czl-settings.php @@ -26,25 +26,25 @@ class CZL_Settings { 'basic' => array( array( 'name' => 'czl_api_url', - 'label' => __('API URL', 'woo-czl-express'), + 'label' => __('API URL', 'czlexpress-for-woocommerce'), 'type' => 'text', 'default' => '', ), array( 'name' => 'czl_username', - 'label' => __('Username', 'woo-czl-express'), + 'label' => __('Username', 'czlexpress-for-woocommerce'), 'type' => 'text', 'default' => '', ), array( 'name' => 'czl_password', - 'label' => __('Password', 'woo-czl-express'), + 'label' => __('Password', 'czlexpress-for-woocommerce'), 'type' => 'password', 'default' => '', ), array( 'name' => 'czl_exchange_rate', - 'label' => __('Exchange Rate', 'woo-czl-express'), + 'label' => __('Exchange Rate', 'czlexpress-for-woocommerce'), 'type' => 'number', 'default' => '1', 'step' => '0.0001', diff --git a/includes/class-czl-shipping-method.php b/includes/class-czl-shipping-method.php index b8305df..b6dc0b0 100644 --- a/includes/class-czl-shipping-method.php +++ b/includes/class-czl-shipping-method.php @@ -8,9 +8,9 @@ class WC_CZL_Shipping_Method extends WC_Shipping_Method { $this->id = 'czl_express'; $this->instance_id = absint($instance_id); - $this->title = __('CZL Express', 'woo-czl-express'); - $this->method_title = __('CZL Express', 'woo-czl-express'); - $this->method_description = __('CZL Express shipping integration', 'woo-czl-express'); + $this->title = __('CZL Express', 'czlexpress-for-woocommerce'); + $this->method_title = __('CZL Express', 'czlexpress-for-woocommerce'); + $this->method_description = __('CZL Express shipping integration', 'czlexpress-for-woocommerce'); $this->supports = array( 'shipping-zones', @@ -42,43 +42,44 @@ class WC_CZL_Shipping_Method extends WC_Shipping_Method { public function init_form_fields() { $this->instance_form_fields = array( 'enabled' => array( - 'title' => __('Enable/Disable', 'woo-czl-express'), + 'title' => __('Enable/Disable', 'czlexpress-for-woocommerce'), 'type' => 'checkbox', - 'label' => __('Enable this shipping method', 'woo-czl-express'), + 'label' => __('Enable this shipping method', 'czlexpress-for-woocommerce'), 'default' => 'yes' ), 'title' => array( - 'title' => __('Method Title', 'woo-czl-express'), + 'title' => __('Method Title', 'czlexpress-for-woocommerce'), 'type' => 'text', - 'description' => __('This controls the title which the user sees during checkout.', 'woo-czl-express'), - 'default' => __('CZL Express', 'woo-czl-express'), + 'description' => __('This controls the title which the user sees during checkout.', 'czlexpress-for-woocommerce'), + 'default' => __('CZL Express', 'czlexpress-for-woocommerce'), 'desc_tip' => true ), 'show_all_rates' => array( - 'title' => __('显示方式', 'woo-czl-express'), + 'title' => __('Display Mode', 'czlexpress-for-woocommerce'), 'type' => 'select', - 'description' => __('选择是显示分组运费还是显示所有具体线路', 'woo-czl-express'), + 'description' => __('Choose to display grouped shipping rates or all specific routes', 'czlexpress-for-woocommerce'), 'default' => 'no', 'options' => array( - 'no' => __('显示分组运费', 'woo-czl-express'), - 'yes' => __('显示所有线路', 'woo-czl-express') + 'no' => __('Show Grouped Rates', 'czlexpress-for-woocommerce'), + 'yes' => __('Show All Routes', 'czlexpress-for-woocommerce') ) ), 'sort_by' => array( - 'title' => __('排序方式', 'woo-czl-express'), + 'title' => __('Sort Order', 'czlexpress-for-woocommerce'), 'type' => 'select', - 'description' => __('选择运费显示的排序方式', 'woo-czl-express'), + 'description' => __('Choose how to sort shipping rates', 'czlexpress-for-woocommerce'), 'default' => 'price', 'options' => array( - 'price' => __('按价格排序', 'woo-czl-express'), - 'time' => __('按时效排序', 'woo-czl-express') + 'price' => __('Sort by Price', 'czlexpress-for-woocommerce'), + 'time' => __('Sort by Delivery Time', 'czlexpress-for-woocommerce') ) ), 'exchange_rate' => array( - 'title' => __('汇率设置', 'woo-czl-express'), + 'title' => __('Exchange Rate', 'czlexpress-for-woocommerce'), 'type' => 'text', 'description' => sprintf( - __('设置CNY到%s的汇率。例如:如果1CNY=%s0.14,输入0.14', 'woo-czl-express'), + /* translators: 1: currency code, 2: currency symbol */ + __('Set exchange rate from CNY to %1$s. Example: if 1 CNY = %2$s0.14, enter 0.14', 'czlexpress-for-woocommerce'), get_woocommerce_currency(), get_woocommerce_currency_symbol() ), @@ -144,9 +145,9 @@ class WC_CZL_Shipping_Method extends WC_Shipping_Method { if (is_cart() || is_checkout()) { wp_enqueue_style( 'czl-shipping-method', - WOO_CZL_EXPRESS_URL . 'assets/css/shipping-method.css', + CZL_EXPRESS_URL . 'assets/css/shipping-method.css', array(), - WOO_CZL_EXPRESS_VERSION + CZL_EXPRESS_VERSION ); } } diff --git a/includes/class-czl-tracking.php b/includes/class-czl-tracking.php index 7f5d94b..1ad36d5 100644 --- a/includes/class-czl-tracking.php +++ b/includes/class-czl-tracking.php @@ -100,8 +100,11 @@ class CZL_Tracking { // 更新WooCommerce订单状态 $order = wc_get_order($shipment->order_id); if ($order) { - $order->update_status($new_status, __('Package status updated from tracking info', 'woo-czl-express')); + $order->update_status($new_status, esc_html__('Package status updated from tracking info', 'czlexpress-for-woocommerce')); } + + // 清除相关缓存 + $this->clear_tracking_cache($shipment->id, $tracking_number, $shipment->order_id); } } catch (Exception $e) { @@ -109,6 +112,34 @@ class CZL_Tracking { } } + /** + * 清除运单相关的所有缓存 + * + * @param int $shipment_id 运单ID + * @param string $tracking_number 运单号 + * @param int $order_id 订单ID + */ + public function clear_tracking_cache($shipment_id, $tracking_number, $order_id) { + // 清除运单缓存 + wp_cache_delete('czl_shipment_' . $shipment_id); + wp_cache_delete('czl_tracking_' . $tracking_number); + + // 清除订单相关缓存 + wp_cache_delete('czl_order_shipments_' . $order_id); + wp_cache_delete('czl_order_tracking_' . $order_id); + + // 清除轨迹历史缓存 + wp_cache_delete('czl_tracking_history_' . $shipment_id); + wp_cache_delete('czl_latest_tracking_' . $tracking_number); + + // 清除运单列表缓存 + wp_cache_delete('czl_active_shipments'); + wp_cache_delete('czl_pending_shipments'); + + // 触发缓存清除动作,允许其他部分清除相关缓存 + do_action('czl_tracking_cache_cleared', $shipment_id, $tracking_number, $order_id); + } + /** * 在订单详情页显示跟踪信息 */ @@ -123,16 +154,16 @@ class CZL_Tracking { $tracking_info = $api->get_tracking($tracking_number); if (!empty($tracking_info)) { - echo '

' . __('物流跟踪信息', 'woo-czl-express') . '

'; + echo '

' . esc_html__('物流跟踪信息', 'czlexpress-for-woocommerce') . '

'; echo '
'; - echo '

' . __('运单号:', 'woo-czl-express') . '' . esc_html($tracking_number) . '

'; + echo '

' . esc_html__('运单号:', 'czlexpress-for-woocommerce') . '' . esc_html($tracking_number) . '

'; if (!empty($tracking_info['trackDetails'])) { echo ''; echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; echo ''; foreach ($tracking_info['trackDetails'] as $detail) { @@ -160,7 +191,7 @@ class CZL_Tracking { $tracking_number = get_post_meta($order->get_id(), '_czl_tracking_number', true); if ($tracking_number) { $tracking_url = 'https://exp.czl.net/track/?query=' . urlencode($tracking_number); - echo '

' . __('物流跟踪:', 'woo-czl-express') . ''; + echo '

' . esc_html__('物流跟踪:', 'czlexpress-for-woocommerce') . ''; echo '' . esc_html($tracking_number) . '

'; } } @@ -176,11 +207,11 @@ class CZL_Tracking { ?>
-

+

' . esc_html($tracking_number) . '' ); @@ -191,14 +222,14 @@ class CZL_Tracking { // 显示子单号 $child_numbers = $order->get_meta('_czl_child_numbers'); if (!empty($child_numbers)) { - echo '

' . __('子单号:', 'woo-czl-express') . ' ' . + echo '

' . esc_html__('子单号:', 'czlexpress-for-woocommerce') . ' ' . implode(', ', array_map('esc_html', $child_numbers)) . '

'; } // 显示参考号 $reference_number = $order->get_meta('_czl_reference_number'); if (!empty($reference_number)) { - echo '

' . __('参考号:', 'woo-czl-express') . ' ' . + echo '

' . esc_html__('参考号:', 'czlexpress-for-woocommerce') . ' ' . esc_html($reference_number) . '

'; } @@ -208,32 +239,32 @@ class CZL_Tracking { $remote_text = ''; switch ($is_remote) { case 'Y': - $remote_text = __('偏远地区', 'woo-czl-express'); + $remote_text = esc_html__('偏远地区', 'czlexpress-for-woocommerce'); break; case 'A': - $remote_text = __('FedEx偏远A级', 'woo-czl-express'); + $remote_text = esc_html__('FedEx偏远A级', 'czlexpress-for-woocommerce'); break; case 'B': - $remote_text = __('FedEx偏远B级', 'woo-czl-express'); + $remote_text = esc_html__('FedEx偏远B级', 'czlexpress-for-woocommerce'); break; case 'C': - $remote_text = __('FedEx偏远C级', 'woo-czl-express'); + $remote_text = esc_html__('FedEx偏远C级', 'czlexpress-for-woocommerce'); break; case 'N': - $remote_text = __('非偏远地区', 'woo-czl-express'); + $remote_text = esc_html__('非偏远地区', 'czlexpress-for-woocommerce'); break; } if ($remote_text) { - echo '

' . __('地区类型:', 'woo-czl-express') . ' ' . - esc_html($remote_text) . '

'; + echo '

' . esc_html__('地区类型:', 'czlexpress-for-woocommerce') . ' ' . + $remote_text . '

'; } } // 显示住宅信息 $is_residential = $order->get_meta('_czl_is_residential'); if ($is_residential === 'Y') { - echo '

' . __('地址类型:', 'woo-czl-express') . ' ' . - __('住宅地址', 'woo-czl-express') . '

'; + echo '

' . esc_html__('地址类型:', 'czlexpress-for-woocommerce') . ' ' . + esc_html__('住宅地址', 'czlexpress-for-woocommerce') . '

'; } // 显示轨迹信息 @@ -241,7 +272,7 @@ class CZL_Tracking { if (!empty($tracking_history['trackDetails'])) { ?>
-

+

diff --git a/includes/class-woo-czl-express.php b/includes/class-czlexpress.php similarity index 76% rename from includes/class-woo-czl-express.php rename to includes/class-czlexpress.php index 5080577..fce49d7 100644 --- a/includes/class-woo-czl-express.php +++ b/includes/class-czlexpress.php @@ -1,5 +1,8 @@ init(); add_action('admin_init', array($this, 'register_settings')); add_action('wp_ajax_czl_test_connection', array($this, 'handle_test_connection')); @@ -39,7 +41,7 @@ class WooCzlExpress { // 添加状态迁移钩子 add_action('init', array($this, 'migrate_order_statuses'), 20); - // 保留批量创建功能,因为这是我们自己的订单管理页面的功能 + // 保留批量创建功能 add_action('wp_ajax_czl_bulk_create_shipment', array($this, 'handle_bulk_create_shipment')); } @@ -58,17 +60,17 @@ class WooCzlExpress { } private function load_dependencies() { - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-api.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-rate-calculator.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-shipping-method.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-install.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-settings.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-order-handler.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-order-data.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-label.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-tracking.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-product-fields.php'; - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-order.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-api.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-rate-calculator.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-shipping-method.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-install.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-settings.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-order-handler.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-order-data.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-label.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-tracking.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-product-fields.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-order.php'; } private function init_hooks() { @@ -91,7 +93,7 @@ class WooCzlExpress { public function init_shipping_method() { if (!class_exists('WC_CZL_Shipping_Method')) { - require_once WOO_CZL_EXPRESS_PATH . 'includes/class-czl-shipping-method.php'; + require_once CZL_EXPRESS_PATH . 'includes/class-czl-shipping-method.php'; } } @@ -104,45 +106,45 @@ class WooCzlExpress { public function add_admin_menu() { add_menu_page( - __('CZL Express', 'woo-czl-express'), - __('CZL Express', 'woo-czl-express'), + esc_html__('CZL Express', 'czlexpress-for-woocommerce'), + esc_html__('CZL Express', 'czlexpress-for-woocommerce'), 'manage_woocommerce', - 'woo-czl-express', + 'czlexpress-for-woocommerce', array($this, 'render_settings_page'), 'dashicons-airplane' ); add_submenu_page( - 'woo-czl-express', - __('基本设置', 'woo-czl-express'), - __('基本设置', 'woo-czl-express'), + 'czlexpress-for-woocommerce', + esc_html__('基本设置', 'czlexpress-for-woocommerce'), + esc_html__('基本设置', 'czlexpress-for-woocommerce'), 'manage_woocommerce', - 'woo-czl-express', + 'czlexpress-for-woocommerce', array($this, 'render_settings_page') ); add_submenu_page( - 'woo-czl-express', - __('订单管理', 'woo-czl-express'), - __('订单管理', 'woo-czl-express'), + 'czlexpress-for-woocommerce', + esc_html__('订单管理', 'czlexpress-for-woocommerce'), + esc_html__('订单管理', 'czlexpress-for-woocommerce'), 'manage_woocommerce', 'czl-express-orders', array($this, 'render_orders_page') ); add_submenu_page( - 'woo-czl-express', - __('产品分组', 'woo-czl-express'), - __('产品分组', 'woo-czl-express'), + 'czlexpress-for-woocommerce', + esc_html__('产品分组', 'czlexpress-for-woocommerce'), + esc_html__('产品分组', 'czlexpress-for-woocommerce'), 'manage_options', 'czl-product-groups', array($this, 'render_product_groups_page') ); add_submenu_page( - 'woo-czl-express', - __('汇率设置', 'woo-czl-express'), - __('汇率设置', 'woo-czl-express'), + 'czlexpress-for-woocommerce', + esc_html__('汇率设置', 'czlexpress-for-woocommerce'), + esc_html__('汇率设置', 'czlexpress-for-woocommerce'), 'manage_options', 'czl-exchange-rates', array($this, 'render_exchange_rates_page') @@ -171,15 +173,15 @@ class WooCzlExpress { } update_option('czl_product_groups', $groups); - add_settings_error('czl_messages', 'czl_message', __('产品分组设置已保存', 'woo-czl-express'), 'updated'); + add_settings_error('czl_messages', 'czl_message', esc_html__('产品分组设置已保存', 'czlexpress-for-woocommerce'), 'updated'); } // 显示设置页面 - require_once WOO_CZL_EXPRESS_PATH . 'admin/views/product-groups.php'; + require_once CZL_EXPRESS_PATH . 'admin/views/product-groups.php'; } public function admin_page() { - require_once WOO_CZL_EXPRESS_PATH . 'admin/views/admin-page.php'; + require_once CZL_EXPRESS_PATH . 'admin/views/admin-page.php'; } /** @@ -190,9 +192,9 @@ class WooCzlExpress { $tracking_number = get_post_meta($order->get_id(), '_czl_tracking_number', true); if ($tracking_number) { - $actions['czl_cancel_shipment'] = __('取消CZL运单', 'woo-czl-express'); + $actions['czl_cancel_shipment'] = esc_html__('取消CZL运单', 'czlexpress-for-woocommerce'); } else { - $actions['czl_create_shipment'] = __('创建CZL运单', 'woo-czl-express'); + $actions['czl_create_shipment'] = esc_html__('创建CZL运单', 'czlexpress-for-woocommerce'); } return $actions; @@ -218,7 +220,7 @@ class WooCzlExpress { // 添加设置分节 add_settings_section( 'czl_api_settings', - __('API设置', 'woo-czl-express'), + esc_html__('API设置', 'czlexpress-for-woocommerce'), null, 'czl_options' ); @@ -226,7 +228,7 @@ class WooCzlExpress { // 添加设置字段 add_settings_field( 'czl_username', - __('用户名', 'woo-czl-express'), + esc_html__('用户名', 'czlexpress-for-woocommerce'), array($this, 'username_field_callback'), 'czl_options', 'czl_api_settings' @@ -234,7 +236,7 @@ class WooCzlExpress { add_settings_field( 'czl_password', - __('密码', 'woo-czl-express'), + esc_html__('密码', 'czlexpress-for-woocommerce'), array($this, 'password_field_callback'), 'czl_options', 'czl_api_settings' @@ -243,14 +245,14 @@ class WooCzlExpress { // 添加运费调整设置分节 add_settings_section( 'czl_rate_settings', - __('运费设置', 'woo-czl-express'), + esc_html__('运费设置', 'czlexpress-for-woocommerce'), null, 'czl_options' ); add_settings_field( 'czl_rate_adjustment', - __('运费调整公式', 'woo-czl-express'), + esc_html__('运费调整公式', 'czlexpress-for-woocommerce'), array($this, 'rate_adjustment_field_callback'), 'czl_options', 'czl_rate_settings' @@ -272,11 +274,11 @@ class WooCzlExpress { ?>

-
+
- 10% + 10 (运费乘以1.1后加10)
- 20% (运费乘以1.2)
- +15 (运费加15)
- +

__('请先配置API账号和密码', 'woo-czl-express') + 'message' => esc_html__('请先配置API账号和密码', 'czlexpress-for-woocommerce') )); } @@ -311,11 +313,11 @@ class WooCzlExpress { if (!empty($data) && isset($data['code']) && $data['code'] == 200) { wp_send_json_success(array( - 'message' => __('API连接测试成功', 'woo-czl-express') + 'message' => esc_html__('API连接测试成功', 'czlexpress-for-woocommerce') )); } else { wp_send_json_error(array( - 'message' => __('API连接测试失败,请检查账号密码是否正确', 'woo-czl-express') + 'message' => esc_html__('API连接测试失败,请检查账号密码是否正确', 'czlexpress-for-woocommerce') )); } } @@ -326,7 +328,7 @@ class WooCzlExpress { } // 显示设置页面 - require_once WOO_CZL_EXPRESS_PATH . 'admin/views/settings.php'; + require_once CZL_EXPRESS_PATH . 'admin/views/settings.php'; } public function render_exchange_rates_page() { @@ -352,11 +354,11 @@ class WooCzlExpress { } } - add_settings_error('czl_messages', 'czl_message', __('汇率设置已保存', 'woo-czl-express'), 'updated'); + add_settings_error('czl_messages', 'czl_message', esc_html__('汇率设置已保存', 'czlexpress-for-woocommerce'), 'updated'); } // 显示设置页面 - require_once WOO_CZL_EXPRESS_PATH . 'admin/views/exchange-rates.php'; + require_once CZL_EXPRESS_PATH . 'admin/views/exchange-rates.php'; } /** @@ -371,23 +373,31 @@ class WooCzlExpress { } register_post_status('wc-in_transit', array( - 'label' => _x('In Transit', 'Order status', 'woo-czl-express'), + 'label' => _x('In Transit', 'Order status', 'czlexpress-for-woocommerce'), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, - 'label_count' => _n_noop('In Transit (%s)', - 'In Transit (%s)', 'woo-czl-express') + /* translators: %s: number of orders in transit */ + 'label_count' => _n_noop( + 'In Transit (%s)', + 'In Transit (%s)', + 'czlexpress-for-woocommerce' + ) )); register_post_status('wc-delivered', array( - 'label' => _x('Delivered', 'Order status', 'woo-czl-express'), + 'label' => _x('Delivered', 'Order status', 'czlexpress-for-woocommerce'), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, - 'label_count' => _n_noop('Delivered (%s)', - 'Delivered (%s)', 'woo-czl-express') + /* translators: %s: number of delivered orders */ + 'label_count' => _n_noop( + 'Delivered (%s)', + 'Delivered (%s)', + 'czlexpress-for-woocommerce' + ) )); $registered = true; @@ -405,8 +415,8 @@ class WooCzlExpress { } $new_statuses = array( - 'wc-in_transit' => _x('In Transit', 'Order status', 'woo-czl-express'), - 'wc-delivered' => _x('Delivered', 'Order status', 'woo-czl-express') + 'wc-in_transit' => _x('In Transit', 'Order status', 'czlexpress-for-woocommerce'), + 'wc-delivered' => _x('Delivered', 'Order status', 'czlexpress-for-woocommerce') ); $order_statuses = array_merge($order_statuses, $new_statuses); @@ -430,12 +440,12 @@ class WooCzlExpress { } ?> -

+

' . esc_html($tracking_number) . '' ); @@ -483,11 +493,11 @@ class WooCzlExpress { ?>

-

+

' . esc_html($tracking_number) . '' ); @@ -504,13 +514,13 @@ class WooCzlExpress { // 检查权限 if (!current_user_can('manage_woocommerce')) { - throw new Exception(__('权限不足', 'woo-czl-express')); + throw new Exception(esc_html__('权限不足', 'czlexpress-for-woocommerce')); } // 验证订单ID $order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0; if (!$order_id) { - throw new Exception(__('无效的订单ID', 'woo-czl-express')); + throw new Exception(esc_html__('无效的订单ID', 'czlexpress-for-woocommerce')); } // 获取WooCommerce订单对象 @@ -525,7 +535,7 @@ class WooCzlExpress { if (!empty($result['tracking_number'])) { wp_send_json_success(array( - 'message' => __('运单创建成功', 'woo-czl-express'), + 'message' => esc_html__('运单创建成功', 'czlexpress-for-woocommerce'), 'tracking_number' => $result['tracking_number'] )); } else { @@ -537,14 +547,14 @@ class WooCzlExpress { if (isset($order)) { $order->add_order_note( sprintf( - __('CZL Express运单创建失败: %s', 'woo-czl-express'), + esc_html__('CZL Express运单创建失败: %s', 'czlexpress-for-woocommerce'), $e->getMessage() ), true ); } wp_send_json_error(array( - 'message' => $e->getMessage() // 直接返回错误信息 + 'message' => $e->getMessage() )); } } @@ -558,13 +568,13 @@ class WooCzlExpress { check_ajax_referer('czl_bulk_create_shipment', 'nonce'); if (!current_user_can('manage_woocommerce')) { - throw new Exception(__('权限不足', 'woo-czl-express')); + throw new Exception(esc_html__('权限不足', 'czlexpress-for-woocommerce')); } // 获取订单ID $order_ids = isset($_POST['order_ids']) ? array_map('intval', (array)$_POST['order_ids']) : array(); if (empty($order_ids)) { - throw new Exception(__('请选择订单', 'woo-czl-express')); + throw new Exception(esc_html__('请选择订单', 'czlexpress-for-woocommerce')); } $success = 0; @@ -589,7 +599,7 @@ class WooCzlExpress { wp_send_json_success(array( 'message' => sprintf( - __('处理完成。成功:%d,失败:%d', 'woo-czl-express'), + esc_html__('处理完成。成功:%1$d,失败:%2$d', 'czlexpress-for-woocommerce'), $success, $failed ), @@ -609,11 +619,11 @@ class WooCzlExpress { public function render_orders_page() { // 检查权限 if (!current_user_can('manage_woocommerce')) { - wp_die(__('您没有足够的权限访问此页面', 'woo-czl-express')); + wp_die(esc_html__('您没有足够的权限访问此页面', 'czlexpress-for-woocommerce')); } // 加载订单列表页面模板 - require_once WOO_CZL_EXPRESS_PATH . 'admin/views/orders.php'; + require_once CZL_EXPRESS_PATH . 'admin/views/orders.php'; } /** diff --git a/includes/class-wc-czlexpress-order.php b/includes/class-wc-czlexpress-order.php deleted file mode 100644 index de91735..0000000 --- a/includes/class-wc-czlexpress-order.php +++ /dev/null @@ -1,27 +0,0 @@ -class WC_CZLExpress_Order { - - public function save_tracking_info($order_id, $tracking_number, $label_url) { - // 使用新的HPOS API保存跟踪信息 - $order = wc_get_order($order_id); - - if ($order) { - // 使用新的元数据API - $order->update_meta_data('_czlexpress_tracking_number', $tracking_number); - $order->update_meta_data('_czlexpress_label_url', $label_url); - $order->save(); - } - } - - public function get_tracking_info($order_id) { - $order = wc_get_order($order_id); - - if ($order) { - return array( - 'tracking_number' => $order->get_meta('_czlexpress_tracking_number'), - 'label_url' => $order->get_meta('_czlexpress_label_url') - ); - } - - return false; - } -} \ No newline at end of file diff --git a/includes/class-wc-czlexpress-orders-list.php b/includes/class-wc-czlexpress-orders-list.php deleted file mode 100644 index 8b80b53..0000000 --- a/includes/class-wc-czlexpress-orders-list.php +++ /dev/null @@ -1,13 +0,0 @@ -class WC_CZLExpress_Orders_List { - - public function get_orders($args = array()) { - // 使用新的订单查询API - $query = new \Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableQuery($args); - return $query->get_orders(); - } - - public function get_order_items($order_id) { - $order = wc_get_order($order_id); - return $order ? $order->get_items() : array(); - } -} \ No newline at end of file diff --git a/includes/class-wc-czlexpress-shipping.php b/includes/class-wc-czlexpress-shipping.php deleted file mode 100644 index b0f72b1..0000000 --- a/includes/class-wc-czlexpress-shipping.php +++ /dev/null @@ -1,16 +0,0 @@ -class WC_CZLExpress_Shipping { - - public function get_shipping_info($order_id) { - $order = wc_get_order($order_id); - - if ($order) { - return array( - 'weight' => $order->get_meta('_czlexpress_weight'), - 'remote_fee' => $order->get_meta('_czlexpress_remote_fee'), - 'shipping_method' => $order->get_meta('_czlexpress_shipping_method') - ); - } - - return false; - } -} \ No newline at end of file diff --git a/languages/czlexpress-for-woocommerce.pot b/languages/czlexpress-for-woocommerce.pot new file mode 100644 index 0000000..a7cc75a --- /dev/null +++ b/languages/czlexpress-for-woocommerce.pot @@ -0,0 +1,120 @@ +# Copyright (C) 2024 CZL Express +# This file is distributed under the GPL v2 or later. +msgid "" +msgstr "" +"Project-Id-Version: CZL Express for WooCommerce 1.0.0\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/czlexpress-for-woocommerce\n" +"Last-Translator: woodchen \n" +"Language-Team: woodchen \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"POT-Creation-Date: 2024-12-20T10:00:00+00:00\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"X-Generator: WP-CLI 2.8.1\n" +"X-Domain: czlexpress-for-woocommerce\n" + +#. Plugin Name of the plugin +msgid "CZL Express for WooCommerce" +msgstr "" + +#. Plugin URI of the plugin +msgid "https://exp.czl.net" +msgstr "" + +#. Description of the plugin +msgid "CZL Express shipping integration for WooCommerce. Provides real-time shipping rates, shipment creation, and package tracking for CZL Express delivery service." +msgstr "" + +#. Author of the plugin +msgid "CZL Express" +msgstr "" + +#. Author URI of the plugin +msgid "https://exp.czl.net" +msgstr "" + +#: czlexpress-for-woocommerce.php:89 +msgid "CZL Express requires WooCommerce to be installed and active" +msgstr "" + +#: czlexpress-for-woocommerce.php:99 +msgid "CZL Express requires WooCommerce 6.0.0 or higher" +msgstr "" + +#: includes/class-czlexpress.php:123 +msgid "Settings" +msgstr "" + +#: includes/class-czlexpress.php:124 +msgid "Documentation" +msgstr "" + +#: includes/class-czlexpress.php:125 +msgid "Support" +msgstr "" + +#: includes/class-czl-order.php:156 +msgid "Package created successfully" +msgstr "" + +#: includes/class-czl-order.php:158 +msgid "Failed to create package" +msgstr "" + +#: includes/class-czl-order.php:187 +msgid "Tracking information updated successfully" +msgstr "" + +#: includes/class-czl-order.php:189 +msgid "Failed to update tracking information" +msgstr "" + +#: includes/class-czl-order.php:234 +msgctxt "Order status" +msgid "In Transit" +msgstr "" + +#: includes/class-czl-settings.php:45 +msgid "CZL Express API Settings" +msgstr "" + +#: includes/class-czl-settings.php:52 +msgid "Enable/Disable" +msgstr "" + +#: includes/class-czl-settings.php:54 +msgid "Enable this shipping method" +msgstr "" + +#: includes/class-czl-settings.php:58 +msgid "API Key" +msgstr "" + +#: includes/class-czl-settings.php:60 +msgid "Enter your CZL Express API key" +msgstr "" + +#: includes/class-czl-settings.php:64 +msgid "API Secret" +msgstr "" + +#: includes/class-czl-settings.php:66 +msgid "Enter your CZL Express API secret" +msgstr "" + +#: includes/class-czl-settings.php:70 +msgid "Test Mode" +msgstr "" + +#: includes/class-czl-settings.php:72 +msgid "Enable test mode" +msgstr "" + +#: includes/class-czl-settings.php:76 +msgid "Debug Log" +msgstr "" + +#: includes/class-czl-settings.php:78 +msgid "Enable logging" +msgstr "" \ No newline at end of file diff --git a/languages/woo-czl-express-zh_CN.po b/languages/woo-czl-express-zh_CN.po deleted file mode 100644 index 34a3fb7..0000000 --- a/languages/woo-czl-express-zh_CN.po +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (C) 2024 CZL Express -# This file is distributed under the GPL v2 or later. -msgid "" -msgstr "" -"Project-Id-Version: CZL Express for WooCommerce 1.0.0\n" -"Report-Msgid-Bugs-To: https://exp.czl.net\n" -"POT-Creation-Date: 2024-01-01 00:00:00+00:00\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2024-01-01 00:00:00+00:00\n" -"Last-Translator: CZL Express\n" -"Language-Team: CZL Express\n" -"Language: zh_CN\n" -"Plural-Forms: nplurals=1; plural=0;\n" - -#: woocommerce-czlexpress.php:89 -msgid "CZL Express requires WooCommerce to be installed and active" -msgstr "CZL Express 需要安装并激活 WooCommerce" - -#: woocommerce-czlexpress.php:98 -msgid "CZL Express requires WooCommerce 6.0.0 or higher" -msgstr "CZL Express 需要 WooCommerce 6.0.0 或更高版本" - -#: woocommerce-czlexpress.php:142 -msgctxt "Order status" -msgid "In Transit" -msgstr "运输中" - -#: woocommerce-czlexpress.php:187 -msgid "Creating shipment..." -msgstr "正在创建运单..." - -#: woocommerce-czlexpress.php:188 -msgid "Shipment created successfully" -msgstr "运单创建成功" - -#: woocommerce-czlexpress.php:189 -msgid "Failed to create shipment" -msgstr "运单创建失败" - -#: woocommerce-czlexpress.php:199 -msgid "Permission denied" -msgstr "权限不足" - -#: woocommerce-czlexpress.php:203 -msgid "Invalid order ID" -msgstr "无效的订单ID" - -#: woocommerce-czlexpress.php:247 -msgid "Invalid parameters" -msgstr "无效的参数" - -#: woocommerce-czlexpress.php:255 -msgid "Database update failed" -msgstr "数据库更新失败" - -#: woocommerce-czlexpress.php:268 -msgid "Tracking number updated to: %s" -msgstr "跟踪单号已更新为:%s" - -#: woocommerce-czlexpress.php:289 -msgid "Insufficient permissions" -msgstr "权限不足" - -#: woocommerce-czlexpress.php:293 -msgid "Invalid order ID" -msgstr "无效的订单ID" - -#: woocommerce-czlexpress.php:297 -msgid "Update scheduled" -msgstr "更新已计划" - -#: woocommerce-czlexpress.php:341 -msgid "Every 30 minutes" -msgstr "每30分钟" \ No newline at end of file diff --git a/languages/woo-czl-express.pot b/languages/woo-czl-express.pot deleted file mode 100644 index 0150077..0000000 --- a/languages/woo-czl-express.pot +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (C) 2024 CZL Express -# This file is distributed under the GPL v2 or later. -msgid "" -msgstr "" -"Project-Id-Version: CZL Express for WooCommerce 1.0.0\n" -"Report-Msgid-Bugs-To: https://exp.czl.net\n" -"POT-Creation-Date: 2024-01-01 00:00:00+00:00\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2024-MO-DA HO:MI+ZONE\n" -"Last-Translator: CZL Express\n" -"Language-Team: CZL Express\n" - -#: woocommerce-czlexpress.php:89 -msgid "CZL Express requires WooCommerce to be installed and active" -msgstr "" - -#: woocommerce-czlexpress.php:98 -msgid "CZL Express requires WooCommerce 6.0.0 or higher" -msgstr "" - -#: woocommerce-czlexpress.php:142 -msgctxt "Order status" -msgid "In Transit" -msgstr "" - -#: woocommerce-czlexpress.php:187 -msgid "Creating shipment..." -msgstr "" - -#: woocommerce-czlexpress.php:188 -msgid "Shipment created successfully" -msgstr "" - -#: woocommerce-czlexpress.php:189 -msgid "Failed to create shipment" -msgstr "" - -#: woocommerce-czlexpress.php:199 -msgid "Permission denied" -msgstr "" - -#: woocommerce-czlexpress.php:203 -msgid "Invalid order ID" -msgstr "" - -#: woocommerce-czlexpress.php:247 -msgid "Invalid parameters" -msgstr "" - -#: woocommerce-czlexpress.php:255 -msgid "Database update failed" -msgstr "" - -#: woocommerce-czlexpress.php:268 -msgid "Tracking number updated to: %s" -msgstr "" - -#: woocommerce-czlexpress.php:289 -msgid "Insufficient permissions" -msgstr "" - -#: woocommerce-czlexpress.php:293 -msgid "Invalid order ID" -msgstr "" - -#: woocommerce-czlexpress.php:297 -msgid "Update scheduled" -msgstr "" - -#: woocommerce-czlexpress.php:341 -msgid "Every 30 minutes" -msgstr "" \ No newline at end of file diff --git a/readme.md b/readme.md index 10f52d7..ad3ac10 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,6 @@ -# woocommerce-czlexpress +# CZL Express for WooCommerce + +CZL Express shipping integration for WooCommerce. Provides real-time shipping rates, shipment creation, and package tracking. ## 描述 diff --git a/readme.txt b/readme.txt index 52a61fd..b8b0f5e 100644 --- a/readme.txt +++ b/readme.txt @@ -1,128 +1,62 @@ === CZL Express for WooCommerce === Contributors: czlexpress -Tags: woocommerce, shipping, czl express, tracking, delivery, shipping method, china shipping, international shipping +Tags: woocommerce, shipping, tracking, czl express, delivery Requires at least: 5.8 -Tested up to: 6.4.2 -Requires PHP: 7.2 +Tested up to: 6.7 +Requires PHP: 8.0 Stable tag: 1.0.0 License: GPLv2 or later -License URI: https://www.gnu.org/licenses/gpl-2.0.html - -Integrate CZL Express shipping service with your WooCommerce store. Get real-time shipping rates, create shipments, and track packages. +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +CZL Express shipping integration for WooCommerce. Provides real-time shipping rates, shipment creation, and package tracking. == Description == -CZL Express for WooCommerce provides seamless integration between your WooCommerce store and CZL Express shipping service. This plugin helps you automate your shipping process and provide better service to your customers. +CZL Express for WooCommerce integrates CZL Express delivery services with your WooCommerce store. This plugin enables automatic shipping rate calculations, easy shipment creation, and real-time package tracking. + +Features: -= Key Features = * Real-time shipping rates calculation * Automatic shipment creation * Package tracking integration -* Custom product grouping for shipping rates -* Support for multiple currencies (CNY to other currencies) -* Automatic order status updates -* Customer-facing tracking information -* Full HPOS (High-Performance Order Storage) support -* WooCommerce remote logging support -* Multi-language support - -= Advanced Features = -* Custom product grouping for different shipping methods -* Flexible pricing rules with markup support (e.g., "10% + 10") -* Quick order creation in CZL Express system -* Label printing support -* Automatic tracking number synchronization (every 30 minutes) -* Automatic tracking information updates (hourly) -* Customer-visible shipping updates - -= Requirements = -* WordPress 6.0 or higher -* WooCommerce 6.0.0 or higher -* PHP 7.4 or higher -* MySQL 5.6 or higher -* CZL Express account and API credentials +* Order status synchronization +* Bulk shipment processing +* Customizable shipping options == Installation == -1. Upload the plugin files to the `/wp-content/plugins/woocommerce-czlexpress` directory, or install the plugin through the WordPress plugins screen directly. -2. Activate the plugin through the 'Plugins' screen in WordPress. -3. Go to the plugin's settings page and configure your CZL Express API credentials and exchange rate. -4. In WooCommerce > Settings > Shipping, configure your shipping zones: - * Create a new zone - * Select the desired regions - * Add "CZL Express" as a shipping method - * Configure the shipping method settings -5. Go to "CZL Express" > "Product Groups" to set up your product groups: - * Remove default groups if needed - * Add custom groups (e.g., "SF Line", "SF Small Packet") -6. The shipping rates will automatically calculate when customers enter their address. +1. Upload the plugin files to the `/wp-content/plugins/czlexpress-for-woocommerce` directory, or install the plugin through the WordPress plugins screen directly. +2. Activate the plugin through the 'Plugins' screen in WordPress +3. Use the WooCommerce->Settings->Shipping->CZL Express screen to configure the plugin +4. Enter your CZL Express API credentials in the settings == Frequently Asked Questions == = Do I need a CZL Express account? = -Yes, you need a CZL Express account and API credentials to use this plugin. Visit [https://exp.czl.net](https://exp.czl.net) to create an account. +Yes, you need a CZL Express account and API credentials to use this plugin. = How do I get API credentials? = -Contact CZL Express support to obtain your API credentials. +Contact CZL Express customer service to obtain your API credentials. -= Can I test the plugin before going live? = += Is this plugin compatible with the latest WooCommerce version? = -Yes, the plugin includes a test mode that allows you to test the integration without creating real shipments. - -= How are shipping rates calculated? = - -Shipping rates are calculated in real-time based on: -* Package weight and dimensions -* Destination address -* Selected shipping method -* Product grouping settings - -= Can I add a markup to shipping rates? = - -Yes, you can add both percentage and fixed amount markups. For example: -* "10%" - Add 10% to the base rate -* "+ 10" - Add 10 to the base rate -* "10% + 10" - Add 10% plus 10 to the base rate - -= How often is tracking information updated? = - -* Tracking numbers are synced every 30 minutes -* Tracking details are updated hourly -* Manual updates are also available - -= Does it support multiple currencies? = - -Yes, rates are fetched in CNY and automatically converted to your store's currency using the configured exchange rate. +Yes, this plugin is regularly tested and updated to maintain compatibility with the latest WooCommerce version. == Screenshots == -1. Plugin settings page - Configure API credentials and general settings -2. Shipping method configuration - Set up shipping zones and methods -3. Product group management - Create and manage product groups -4. Order with tracking information - View tracking details in orders -5. Shipping rate display - How customers see shipping options -6. Order management - Create shipments and print labels -7. Tracking information - Customer-facing tracking updates +1. Plugin settings page +2. Shipping rate configuration +3. Order management interface +4. Tracking information display == Changelog == = 1.0.0 = * Initial release -* Full WooCommerce HPOS support -* Real-time shipping rates -* Automatic shipment creation -* Package tracking integration -* Product grouping support -* Multi-currency support -* Automatic tracking updates == Upgrade Notice == = 1.0.0 = -Initial release of CZL Express for WooCommerce. - -== Support == - -For support, please visit [https://exp.czl.net](https://exp.czl.net) or contact our support team. \ No newline at end of file +Initial release of CZL Express for WooCommerce plugin. \ No newline at end of file diff --git a/templates/shipping-method-group.php b/templates/shipping-method-group.php index 5135f19..5f9ebfb 100644 --- a/templates/shipping-method-group.php +++ b/templates/shipping-method-group.php @@ -8,14 +8,14 @@ defined('ABSPATH') || exit;

' . __('时间', 'woo-czl-express') . '' . __('地点', 'woo-czl-express') . '' . __('状态', 'woo-czl-express') . '' . esc_html__('时间', 'czlexpress-for-woocommerce') . '' . esc_html__('地点', 'czlexpress-for-woocommerce') . '' . esc_html__('状态', 'czlexpress-for-woocommerce') . '
id, $chosen_method); ?> /> -