Wordpress print_r或来自钩子回调的回声

时间:2016-09-07 17:08:28

标签: php wordpress woocommerce

我想在下面调试一个函数。 print_r和echo也没有显示任何内容。如何打印以下内容: $ 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 $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  ); 

每当我运行该功能时,我都会收到以下woocommerce通知:

SyntaxError: Unexpected token m in JSON at position 0

1 个答案:

答案 0 :(得分:3)

因为您正在执行Ajax请求,所以响应将不会显示在页面上。 echoprint_r()函数正在运行,但是为了查看Ajax响应发生了什么,您需要使用浏览器控制台。

按F12可以访问大多数浏览器的控制台。然后,您将能够看到正在发出的HTTP请求,并可以检查它们发生了什么。