在Woocommerce中创建外部路由的链接

问题描述 投票:4回答:1

在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>";
}

任何帮助表示赞赏。

php wordpress variables woocommerce global
1个回答
1
投票

在你的函数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>";
}

现在它应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.