Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
677 views
in Technique[技术] by (71.8m points)

wordpress - Add order metadata to WooCommerce admin order overview

enter image description here

I am developing a plugin for WooCommerce. I want to override the order details template of admin. i have read about on https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/ , but still I don't understand how to override the order detail template of admin. following is my code:

 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
 if ( ! class_exists( 'Test' ) ) {
   load_plugin_textdomain( 'test', false, dirname( plugin_basename( __FILE__ ) ) . '/' );
}
}
class Test {
public function __construct() {
add_action( 'init', array( $this, 'include_template_functions' ), 20 );
add_action( 'woocommerce_init', array( $this, 'woocommerce_loaded' ) );
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
do_action( 'woocommerce_admin_order_data_after_order_details', 'hello' );
}

public function hello() {
echo "order detail template has loaded";
}

public function include_template_functions() {
include( 'woocommerce-template.php' );
echo "template has loaded";
 }

  public function woocommerce_loaded() {
  }

public function plugins_loaded() {
 }
 }

$GLOBALS['wc_acme'] = new Test();

It's not calling the hook associated with woocommerce_admin_order_data_after_order_details.

Can anyone please suggest or share some example of editing the order details template editing via plugin. Please note that I am referring to the order detail template inside the administrator, where administrator can view the detail of any order from the list.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From my tutorial on customizing WooCommerce checkout fields this is how you'd display some extra order meta data in the Order Details metabox:

// display the extra data in the order admin panel
function kia_display_order_data_in_admin( $order ){  ?>
    <div class="order_data_column">
        <h4><?php _e( 'Extra Details' ); ?></h4>
        <?php 
            echo '<p><strong>' . __( 'Some field' ) . ':</strong>' . get_post_meta( $order->id, '_some_field', true ) . '</p>';
            echo '<p><strong>' . __( 'Another field' ) . ':</strong>' . get_post_meta( $order->id, '_another_field', true ) . '</p>'; ?>
    </div>
<?php }
add_action( 'woocommerce_admin_order_data_after_order_details', 'kia_display_order_data_in_admin' );

This assumes that you have collected the data on checkout and saved the data as post meta for the $order in question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...