我的woocommerce商店中的订单状态正在从处理中变为待定。我想把它记录到文件里。我有这样一个代码:
function log_woocommerce_order_status_change($order_id, $old_status, $new_status) {
$current_datetime = date('Y-m-d H:i:s');
$call_stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 5);
$plugin_info = 'Plugin info not available';
foreach ($call_stack as $trace) {
if (isset($trace['file']) && strpos($trace['file'], 'plugins/') !== false) {
$plugin_info = 'Plugin file: ' . $trace['file'] . ', Line: ' . $trace['line'];
break;
}
}
$log_message = "[$current_datetime] woocommerce_order_status_changed hook called for order ID $order_id. Old status: $old_status, New status: $new_status. Triggered by: $plugin_info";
error_log($log_message . PHP_EOL, 3, WP_CONTENT_DIR . '/woocommerce_order_status.log', FILE_APPEND);
}
add_action('woocommerce_order_status_changed', 'log_woocommerce_order_status_change', 10, 3);
但是每次状态改变,它都会给我同样的结果:
woocommerce_order_status_changed hook called for order ID 13232. Old status: processing, New status: pending. Triggered by: Plugin file: /home/maisonpa/domains/my-theme/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php, Line: 405
是否可以获取直接调用函数“woocommerce_order_status_changed”的插件/文件的名称,而不是存储它的文件?
1条答案
按热度按时间kpbwa7wx1#
对于这个问题,首先检查woocommerce设置,
检查WooCommerce设置:转到您的WooCommerce设置并检查“WooCommerce”>“设置”>“常规”选项卡下的“订单状态”设置。确保新订单的默认订单状态设置为“正在处理”(如果需要)。
谢谢