Php Wordpress从钩子回调中打印或回显
我想调试下面的一个函数。但打印或回音没有显示任何内容。如何打印以下内容: $order还是$paypal_argsPhp Wordpress从钩子回调中打印或回显,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想调试下面的一个函数。但打印或回音没有显示任何内容。如何打印以下内容: $order还是$paypal_args function custom_override_paypal_email1( $paypal_args, $order ) { print_r($paypal_args); print_r($order); // die(); global $woocommerce; foreach ( $order->get_items() as
function custom_override_paypal_email1( $paypal_args, $order ) {
print_r($paypal_args);
print_r($order);
// die();
global $woocommerce;
foreach ( $order->get_items() as $product ) {
$terms = get_the_terms($product['product_id'],'product_cat');
if (!is_null($terms)){
if(count($terms)>0)
{
//get first one
$term = $terms[0];
if(strtolower($catName)==='ethics'){
$paypal_args['business'] = "zzz@zzz.example.com";
}
else{
// $t = strval($term);
$paypal_args['business'] = $t ."yyy@yyy.example.com";
}
}
}
// break;
}
// $woocommerce->add_error( sprintf( "You must add a minimum of %s %s's to your cart to proceed." , 1, "T" ) );
return $paypal_args;
}
add_filter( 'woocommerce_paypal_args' , 'custom_override_paypal_email1', 10, 2 );
无论何时运行该函数,我都会收到以下通知:
SyntaxError: Unexpected token m in JSON at position 0
因为您正在执行Ajax请求,所以响应不会显示在页面上。
echo
或print\r()
函数正在工作,但要查看Ajax响应的情况,需要使用浏览器控制台
按F12键可以在大多数浏览器上访问控制台。然后,您将能够看到正在发出的HTTP请求,并可以检查它们发生了什么。您确定函数确实正在被调用吗?
die()
有效吗?每当我添加die函数时,该函数将无限期挂起。我仍然看不到任何输出。我怀疑这个函数可能是通过ajax执行的,这就是为什么我看不到任何东西??代码$paypal_args['business']=”xxx@xxx.com"; 如果die导致某些东西无限期挂起,我假设您正在执行一个ajax请求,而die正在阻止任何响应。在这种情况下,您可以将print\r()
放回,您需要使用浏览器控制台检查ajax调用时发生的情况。谢谢。你能把它作为答案提交吗?我使用error\u log(json\u encode($array))
并在WP config.php
中启用WP\u DEBUG\u log
,当我需要在一个不适合print\u f()
的地方看到数组(或任何其他变量)时,这正是我解决问题的方法。