在Woocommerce中,我正在尝试为pdf生成创建外部链接。
我在process_payment
处理付款并且我将json结果传递给thankyou_page
函数,但由于某种原因,json返回传递给thankyou_page
函数时返回null。
按照源代码:
$response = json_decode($json_response, true);
$linkBoleto = $response['pdfBoleto'];
function thankyou_page($order_id){
echo "<a href='".$linkBoleto."' target='_blank'>Boleto</a>";
}
任何帮助表示赞赏。
在你的函数thankyou_page
中,需要定义变量$linkBoleto
:
1)您可以将其作为参数包含在函数中,例如:
$response = json_decode($json_response, true);
$linkBoleto = $response['pdfBoleto'];
function thankyou_page($order_id, $linkBoleto){
echo "<a href='".$linkBoleto."' target='_blank'>Boleto</a>";
}
2)您也可以使用global
将其包含在函数中:
$response = json_decode($json_response, true);
$linkBoleto = $response['pdfBoleto'];
function thankyou_page($order_id){
global $linkBoleto;
echo "<a href='".$linkBoleto."' target='_blank'>Boleto</a>";
}
现在它应该工作。