Gabriel Barreto
Gabriel Barreto

Reputation: 31

Creating a link to external route in Woocommerce

In Woocommerce I am trying to create an external link for pdf generation.

I'm processing the payment in process_payment and I'm passing the json result to the thankyou_page function, but for some reason the json return when passed to the thankyou_page function gets null.

Follow the source code:

$response = json_decode($json_response, true);
$linkBoleto = $response['pdfBoleto'];

function thankyou_page($order_id){
    echo "<a href='".$linkBoleto."' target='_blank'>Boleto</a>";
}

Any help is appreciated.

Upvotes: 3

Views: 43

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253868

In your function thankyou_page the variable $linkBoleto need to be defined:

1) You can include it as an argument in the function, like:

$response = json_decode($json_response, true);
$linkBoleto = $response['pdfBoleto'];

function thankyou_page($order_id, $linkBoleto){
    echo "<a href='".$linkBoleto."' target='_blank'>Boleto</a>";
}

2) You can include it in the function also using global like:

$response = json_decode($json_response, true);
$linkBoleto = $response['pdfBoleto'];

function thankyou_page($order_id){
    global $linkBoleto;

    echo "<a href='".$linkBoleto."' target='_blank'>Boleto</a>";
}

Now it should work.

Upvotes: 1

Related Questions