在 Woocommerce 中,我正在尝试创建用于生成 pdf 的外部链接。
我在 process_payment
中处理付款,我将 json 结果传递给 thankyou_page
函数,但由于某种原因,传递给 时返回 json code>thankyou_page
函数为空。
跟随源码:
$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>";
}
现在它应该可以工作了。
关于php - 在 Woocommerce 中创建指向外部路由的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55065336/