0

I'm developing a theme for woocommerce website. My problem is that to show order details on my account and thank you page, woocommerce only has the following template file:

/wp-content/plugins/woocommerce/templates/order/order-details.php

How to create two different template files for thank you page and my account page to show order details.

1
  1. Create/copy an override template file in your-theme/woocommerce/order/order-details-thankyou.php
  2. In functions.php add this block of code:

    function woocommerce_order_details_table_thankyou( $order_id ) {
        if ( ! $order_id ) {
            return;
        }
    
        wc_get_template( 'order/order-details-thankyou.php', array(
            'order_id' => $order_id,
        ) );
    }
    
    remove_action( 'woocommerce_thankyou', 'woocommerce_order_details_table', 10 );
    add_action( 'woocommerce_thankyou', 'woocommerce_order_details_table_thankyou', 10 );
    

This is perfectly fine way to unhook the default template file and hook your own. Now you have two template files for showing the order details, the default one order-details.php and a new one order-details-thankyou.php.

Btw, I hope you are aware that it is really bad practice to edit the plugin template files directly inside the plugin directory. You should always override them by copying them to you theme directory. For WooCommerce, this directory is your-theme/woocommerce/... (omit the templates directory). You are probably aware of this, but it doesn't hurt to be reassured.

  • 1
    Thank you!. This works perfectly. I'm working on theme directory but added plugin directory to clarity of the question. :) – Janaka Dombawela Oct 29 '18 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.