我正在为WooCommerce编程一个支付插件。为了测试它,我需要打印$response
. 我试过这个echo
, print_r
和var_dump
, 但当我进行购买过程时,它不会在任何一面打印。
What can I do to visualize this content when buying a product?(输入卡片详细信息并完成购买流程后,我需要查看这些值)
部分插件代码:
$payload = array(
"key_id" => $key_id,
"hash" => $hash,
"time" => $time,
"amount" => $customer_order->order_total,
"ccnumber" => str_replace( array(\' \', \'-\' ), \'\', $_POST[\'bac_payment-card-number\'] ),
"ccexp" => str_replace( array( \'/\', \' \'), \'\', $_POST[\'bac_payment-card-expiry\'] ),
"orderid" => $orderid,
"cvv" => ( isset( $_POST[\'bac_payment-card-cvc\'] ) ) ? $_POST[\'bac_payment-card-cvc\'] : \'\',
"type" => "auth",);
// Send this payload to Authorize.net for processing
$response = wp_remote_post( $environment_url, array(
\'method\' => \'POST\',
\'body\' => http_build_query( $payload ),
\'timeout\' => 90,
\'sslverify\' => false,
) );
//***********
//when I make a purchase I need to see these values
//************
var_dump($response);
var_dump($response_body);
die()
SO网友:butlerblog
这些是您需要写入日志才能查看的值。
为了做到这一点,请确保在wp配置中启用了调试。php:
define( \'WP_DEBUG\', true );
define( \'WP_DEBUG_LOG\', true );
然后,使用以下命令
utility function 将值写入日志。你可以用
error_log( $value )
, bu此实用程序将处理数组/对象,而无需担心日志文件的数组格式:
function write_log( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
现在,而不是
var_dump()
, 你可以打电话
write_log()
将结果转储到/wp-content/error。日志:
write_log($response);
write_log($response_body);
(
There was a similar type of question yesterday, 如果您想查看其他详细信息。)