Is it possible to vardump the variable inside the action function? i am not able to echo or see results when i am doing so.

This is not a woo commerce question but i am having problems with

add_action('woocommerce_order_status_changed','wc_order_uppdate_to_cancelled_status', 20, 4);
  • 1
    Where is the var_dump in this? To be honest I don't really understand your question. You can use var_dump() inside the function that is called from that action, yes – kero Oct 19 at 13:24
  • @kero yes, that question was whether i can use var_dump() inside the function that is called from that action..i am changing the order status from the backend for above function but does not show the any var_dump values...may be it is effecting the users only..nothing in admin side ..thanks for the confirmation – Latheesh V M Villa Oct 19 at 13:28
up vote 2 down vote accepted

If you want to use debugging from an action where you won't see the output, you can send things to error_log. First, you need to enable debug logging. In your /wp-config.php add the lines:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

This will create a file called /wp-content/debug.log

Next, in your code, add some calls to error_log and var_export:

add_action( 'init', 'some_function' );

function some_function( $var ) {
    error_log( var_export( $var, 1 ) );
}

Now, when init runs our function, the contents of $var will be dumped to /wp-content/debug.log. Note the second parameter to var_export says to return the output instead of trying to send it to be displayed.

  • 1
    thank you exactly what i was looking for..if my question is confusing and if can be improved please feel free to do so. – Latheesh V M Villa Oct 19 at 14:00
  • hi, ` error_log( var_export( $var, 1 ) );` what is parameter 1 in this code? – Latheesh V M Villa Oct 19 at 14:10
  • 1
    See the second parameter to var_export on PHP.net. When the second parameter is truthy (e.g. 1, true, etc), var_export will return it's output instead of just dumping it to the screen. – phatskat Oct 19 at 14:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.