简体   繁体   中英

Woocommerce - redirect to order-received page but order details are not shown

I implement WC_Payment_Gateway to customize my payment gateway which redirect checkout page to bank page for credit card process.

After credit card is paid, the bank page redirect user to a callback page I set. I do some payment status checking then redirect user to thankyou.php by using javascript.

 <script>
     function myFunction() {
         window.location.href = "https://sib-skincare.com/checkout/order-received";
     };
 </script>

Then it only shows a simple successful message like this在此处输入图像描述

After I check the thankyou.php page, I notice one thing. The page firstly check if ( $order ) exits then it shows more order detail information otherwise it will only show "Thank you. Your order has been received."

My question is when the $order variable is set? If I don't insert some code in the thankyou.php page to get order_id from session and instance $order object. The object will always be none therefore order detail are not shown.

https://github.com/woocommerce/woocommerce/blob/master/templates/checkout/thankyou.php

defined( 'ABSPATH' ) || exit;
?>

<div class="woocommerce-order">

<?php
if ( $order ) :
    do_action( 'woocommerce_before_thankyou', $order->get_id() );
    ......
    .......

<?php else : ?>

    <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', 'woocommerce' ), null ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>

<?php endif; ?>

</div>

You can make sure that you are passing order id and the secured key like this in the url:

https://site-url/checkout/order-received/2878/?key=wc_order_u9DmQCpfdEhcW

Order id you can get it from the process you are doing, and if you are not getting the key then you can grab it from postmeta table.

If you pass it like this, then you will see a normal thank you page with all details of order.

As per your current url, there is no identification of order in url, so it's showing you a generic thank you page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM