$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>woocommerce offtopic - Different files for order details|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

woocommerce offtopic - Different files for order details

matteradmin9PV0评论

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.

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.

Share Improve this question edited Oct 29, 2018 at 8:46 Janaka Dombawela asked Oct 29, 2018 at 8:17 Janaka DombawelaJanaka Dombawela 1035 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

Post a comment

comment list (0)

  1. No comments so far