【问题标题】:Uncaught ArgumentCountError: Too few arguments to function order_completed(). on woocommerce_order_status_completed hook未捕获的 ArgumentCountError:函数 order_completed() 的参数太少。在 woocommerce_order_status_completed 钩子上
【发布时间】:2022-01-07 08:30:09
【问题描述】:

我收到以下错误:

[2021 年 11 月 30 日 16:08:47 UTC] PHP 致命错误:未捕获的 ArgumentCountError:函数 order_completed() 的参数太少,1 传入 /home/brantsho/public_html/wp-includes/class-wp-第 305 行的 hook.php 和 /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/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 在 /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
   ) ); 
    
  }
}

请你帮我整理一下..

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce orders


    【解决方案1】:

    您已将4 参数传递给您的回调函数,但在您的挂钩中您只指定了1

    替换

    add_action( 'woocommerce_order_status_completed', 'order_completed',10,1);
    

    add_action( 'woocommerce_order_status_completed', 'order_completed', 10, 4);
    

    【讨论】:

    • 救命...愚蠢的错误
    猜你喜欢
    • 2019-06-01
    • 2018-10-11
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多