Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在WooCommerce中计算配送时,避免在update_checkout事件上发生致命错误_Php_Ajax_Wordpress_Woocommerce_Hook Woocommerce - Fatal编程技术网

Php 在WooCommerce中计算配送时,避免在update_checkout事件上发生致命错误

Php 在WooCommerce中计算配送时,避免在update_checkout事件上发生致命错误,php,ajax,wordpress,woocommerce,hook-woocommerce,Php,Ajax,Wordpress,Woocommerce,Hook Woocommerce,我想在触发update_checkout时计算发货量。我在我的插件函数中使用了以下代码 function action_woocommerce_checkout_update_order_review($array, $int) { WC()->cart->calculate_shipping(); return; } add_action('woocommerce_checkout_update_order_review', 'action_woocommerce_

我想在触发update_checkout时计算发货量。我在我的插件函数中使用了以下代码

function action_woocommerce_checkout_update_order_review($array, $int)
{
    WC()->cart->calculate_shipping();
    return;
}
add_action('woocommerce_checkout_update_order_review', 'action_woocommerce_checkout_update_order_review', 10, 2);
当我更新签出时,我在AJAX响应中遇到了致命错误

<br />
<b>Fatal error</b>:  Uncaught ArgumentCountError: Too few arguments to function action_woocommerce_checkout_update_order_review(), 1 passed in C:\xampp\htdocs\woo\wp-includes\class-wp-hook.php on line 286 and exactly 2 expected in C:\xampp\htdocs\woo\wp-content\plugins\wooinstant\inc\wooinstant-functions.php:82
Stack trace:
#0 C:\xampp\htdocs\woo\wp-includes\class-wp-hook.php(286): action_woocommerce_checkout_update_order_review('billing_first_n...')
#1 C:\xampp\htdocs\woo\wp-includes\class-wp-hook.php(310): WP_Hook-&gt;apply_filters('', Array)
#2 C:\xampp\htdocs\woo\wp-includes\plugin.php(453): WP_Hook-&gt;do_action(Array)
#3 C:\xampp\htdocs\woo\wp-content\plugins\woocommerce\includes\class-wc-ajax.php(281): do_action('woocommerce_che...', 'billing_first_n...')
#4 C:\xampp\htdocs\woo\wp-includes\class-wp-hook.php(286): WC_AJAX::update_order_review('')
#5 C:\xampp\htdocs\woo\wp-includes\class-wp-hook.php(310): WP_Hook-&gt;apply_filters('', Array)
#6 C:\xampp\htdocs\woo\wp-includes\plugin.php(453): WP_Hook-&gt;do_action(Array)
#7 C:\xampp\htd in <b>C:\xampp\htdocs\woo\wp-content\plugins\wooinstant\inc\wooinstant-functions.php</b> on line <b>82</b><br />

致命错误:Uncaught ArgumentCounter错误:函数操作的参数太少\u woocommerce\u checkout\u update\u order\u review(),在第286行的C:\xampp\htdocs\woo\wp includes\class-wp-hook.php中传递了1个参数,在C:\xampp\htdocs\woo\wo\wp content\plugins\wooinstant\inc\wooinstant functions.php:82中正好传递了2个参数 堆栈跟踪: #0 C:\xampp\htdocs\woo\wp includes\class wp hook.php(286):操作\u woocmerce\u checkout\u update\u order\u review('billing\u first\u n…')) #1c:\xampp\htdocs\woo\wp包括\class wp hook.php(310):wp\u hook-apply\u过滤器(“”,数组) #2c:\xampp\htdocs\woo\wp includes\plugin.php(453):wp\u Hook-do\u动作(数组) #3 C:\xampp\htdocs\woo\wp content\plugins\woocmerce\includes\class wc ajax.php(281):执行操作('woocmerce\u che…','billing\u first\u n…')) #4 C:\xampp\htdocs\woo\wp包含\class wp hook.php(286):WC\u AJAX::update\u order\u review(“”) #5c:\xampp\htdocs\woo\wp包含\class wp hook.php(310):wp\u hook-apply\u过滤器(“”,数组) #6c:\xampp\htdocs\woo\wp includes\plugin.php(453):wp\u Hook-do\u动作(数组) #7 C:\xampp\htdocs\woo\wp content\plugins\woodinstant\inc\woodinstant-functions.php中的C:\xampp\htd,第82行

我如何计算更新付款时的运费?非常感谢您的帮助。

woocommerce\u checkout\u update\u order\u review钩子是一个带有唯一参数的动作钩子。因为它是一个动作钩子,所以不需要像过滤器钩子那样返回任何东西

尝试此重新访问的代码版本,测试时没有抛出任何错误:

add_action( 'woocommerce_checkout_update_order_review', 'action_woocommerce_checkout_update_order_review', 10, 1 );
function action_woocommerce_checkout_update_order_review( $posted_data ) {
    WC()->cart->calculate_shipping();
}