ArgumentCountError no capturado: muy pocos argumentos para la función order_completed(). en el gancho woocommerce_order_status_completed

2 minutos de lectura

Avatar de usuario de Haren Sarma
haren sarma

Recibo el siguiente error:

[30-Nov-2021 16:08:47 UTC] Error fatal de PHP: ArgumentCountError no detectado: Muy pocos argumentos para la función order_completed(), 1 pasado en /home/brantsho/public_html/wp-includes/class-wp-hook.php en la línea 305 y exactamente 4 esperados en /home/brantsho/ public_html/wp-content/themes/glowing/functions.php:28 Rastreo de pila: #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_statu s() #7 /home/brantsho/public_html/wp-incl en /home/brantsho/public_html/wp-content/themes/glowing/functions.php en la línea 28

Pero mi functions.php parece estar bien:

<?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
   ) ); 
    
  }
}

por favor me pueden ayudar a solucionarlo..

has pasado 4 argumentos a su función de devolución de llamada, pero en su gancho especificó solo 1.

Reemplazar

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

Con

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

  • salvavidas… error tonto

    – Haren Sarma

    1 de diciembre de 2021 a las 8:06

¿Ha sido útil esta solución?