soliddigital
soliddigital

Reputation: 306

Show Woocommerce order details on custom thank you page

Hi I created custom thank you page for my COD (cash on delivery) payment option. Redirect code below working.

add_action( 'template_redirect', 'thankyou_custom_payment_redirect');
    function thankyou_custom_payment_redirect(){
    if ( is_wc_endpoint_url( 'order-received' ) ) {
        global $wp;

        // Get the order ID
        $order_id =  intval( str_replace( 'checkout/order-received/', '', $wp->request ) );

        // Get an instance of the WC_Order object
        $order = wc_get_order( $order_id );

        // Set HERE your Payment Gateway ID
        if( $order->get_payment_method() == 'cod' ){

            // Set HERE your custom URL path
            wp_redirect( home_url( '/custom-page/' ) );
            exit(); // always exit
        }
    }
}
Now in my /custom-page/ I want to display same details as in Woocommerce order-details.php. I created custom-page.php with(/* Template Name: COD Thank you page */) for my Thank you Page, copied code from original Woocommerce order-details.php but just loads blank page. Can someone help me to do this correctly please. Thank you

Upvotes: 4

Views: 5488

Answers (1)

MistaPrime
MistaPrime

Reputation: 1677

Ensure that your new order-details.php has a URL and that that URL is added inside of WooCommerce > Settings > Advanced > Order Received. In there you would add the slug of that URL of your new order-details page. There are also easier ways to create a custom thank you page using plugins such as this one: https://wordpress.org/plugins/yith-custom-thank-you-page-for-woocommerce/

Upvotes: -3

Related Questions