Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress print_r or echo from within hook callback

I want to debug a function below. The print_r nor echo are not displaying anything though. How can I print the contents of: $order or $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'] = "[email protected]";
                     }
                     else{
                        // $t = strval($term);
                        $paypal_args['business'] = $t ."[email protected]";
                     }
                }
            }
        //  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  ); 

Whenever I run the function I am getting the following woocommerce notice:

SyntaxError: Unexpected token m in JSON at position 0
like image 884
Janusz Chudzynski Avatar asked Jan 22 '26 20:01

Janusz Chudzynski


1 Answers

Because you are performing an Ajax request, the response will not be shown on the page. The echo or print_r() functions are working, but in order to see what is happening with Ajax responses you need to use the browser console.

You can access the console on most browsers by pressing F12. You will then be able to see the HTTP requests being made, and can examine what is happening with them.

like image 122
BadHorsie Avatar answered Jan 25 '26 12:01

BadHorsie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!