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'] = "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 );
Whenever I run the function I am getting the following woocommerce notice:
SyntaxError: Unexpected token m in JSON at position 0
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.