Har*_*rma 4 php wordpress orders woocommerce hook-woocommerce
我收到以下错误:
[2021 年 11 月 30 日 16:08:47 UTC] PHP 致命错误:未捕获的 ArgumentCountError:函数 order_completed() 的参数太少,1 个传入 /home/brantsho/public_html/wp-includes/class-wp-hook.php在第 305 行和 /home/brantsho/public_html/wp-content/themes/glowing/functions.php:28 中预期的第 4 行堆栈跟踪:#0 /home/brantsho/public_html/wp-includes/class-wp-hook。 php(305): order_completed() #1 /home/brantsho/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #2 /home/brantsho/public_html/wp-includes /plugin.php(470): WP_Hook->do_action() #3 /home/brantsho/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php(364): do_action() #4 / home/brantsho/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php(222): WC_Order->status_transition() #5 /home/brantsho/public_html/wp-content/plugins/woocommerce/包括/class-wc-order.php(334): WC_Order->save() #6 /home/brantsho/public_html/wp-content/plugins/woocommerce/includes/class-wc-ajax.php(530): WC_Order ->update_status() #7 /home/brantsho/public_html/wp-incl 在 /home/brantsho/public_html/wp-content/themes/glowing/functions.php 第 28 行
但我的functions.php 看起来不错:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
define('GLOWING_VERSION', '1.0.0');
define('GLOWING_FILE_HANDLER', basename(get_template_directory()) . '-');
/**
* Inlcude theme functions
*/
include_once get_parent_theme_file_path('inc/require-plugin.php');
include_once get_parent_theme_file_path('inc/breadcrumbs.php');
include_once get_parent_theme_file_path('inc/core-functions.php');
include_once get_parent_theme_file_path('inc/template-functions.php');
include_once get_parent_theme_file_path('inc/template-tags.php');
include_once get_parent_theme_file_path('inc/customizer.php');
include_once get_parent_theme_file_path('inc/setup-data.php');
include_once get_parent_theme_file_path('inc/core.php');
include_once get_parent_theme_file_path('inc/elementor.php');
include_once get_parent_theme_file_path('inc/custom-css.php');
if (function_exists('WC')) {
include_once get_parent_theme_file_path('inc/woocommerce.php');
}
add_action( 'woocommerce_order_status_completed', 'order_completed',10,1);
function order_completed($order_id, $old_status, $new_status, $order) {
if( $new_status == "completed" ) {
$order = wc_get_order( $order_id );
$total = $order->get_total();
$coin_avl = $total*25/100;
wp_update_user( array(
'ID' => get_current_user_id(),
'avl_coin' => $coin_avl
) );
}
}
Run Code Online (Sandbox Code Playgroud)
请你帮我解决一下..
您已将4参数传递给回调函数,但在挂钩中您仅指定了1.
代替
add_action( 'woocommerce_order_status_completed', 'order_completed',10,1);
Run Code Online (Sandbox Code Playgroud)
和
add_action( 'woocommerce_order_status_completed', 'order_completed', 10, 4);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1800 次 |
| 最近记录: |