Uncaught ArgumentCountError: Too few arguments to function order_completed(). on woocommerce_order_status_completed hook
Uncaught ArgumentCountError: Too few arguments to function order_completed(). on woocommerce_order_status_completed hook
我收到以下错误:
[30-Nov-2021 16:08:47 UTC] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function order_completed(), 1 passed in /home/brantsho/public_html/wp-includes/class-wp-hook.php on line 305 and exactly 4 expected in /home/brantsho/public_html/wp-content/themes/glowing/functions.php:28
Stack trace:
#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/includes/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 in /home/brantsho/public_html/wp-content/themes/glowing/functions.php on line 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
) );
}
}
请你帮我解决一下..
您已将 4
个参数传递给回调函数,但您在挂钩中仅指定了 1
.
替换
add_action( 'woocommerce_order_status_completed', 'order_completed',10,1);
有
add_action( 'woocommerce_order_status_completed', 'order_completed', 10, 4);
我收到以下错误:
[30-Nov-2021 16:08:47 UTC] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function order_completed(), 1 passed in /home/brantsho/public_html/wp-includes/class-wp-hook.php on line 305 and exactly 4 expected in /home/brantsho/public_html/wp-content/themes/glowing/functions.php:28 Stack trace: #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/includes/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 in /home/brantsho/public_html/wp-content/themes/glowing/functions.php on line 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
) );
}
}
请你帮我解决一下..
您已将 4
个参数传递给回调函数,但您在挂钩中仅指定了 1
.
替换
add_action( 'woocommerce_order_status_completed', 'order_completed',10,1);
有
add_action( 'woocommerce_order_status_completed', 'order_completed', 10, 4);