woocommerce订单详情页添加自定义信息展示

it不难
2022-12-09 / 0 评论 / 17 阅读 / 正在检测是否收录...

前言

代码

订单列表页

// 路径:wp-content/themes/razzi/functions.php
// 在管理员后台订单详细页面也显示一下
add_action( 'woocommerce_admin_order_data_after_order_details', 'brain_display_order_data_in_admin' );
function brain_display_order_data_in_admin( $order ){  ?>
    <div class="order_data_column">
        <h4><?php _e( 'Extra Order Details', 'woocommerce' ); ?></h4>
        <?php
            global $wpdb;
            $order_extra_info = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}superxpay_rapay_data WHERE  orderid = '".$order->id."'");

            echo '<p><strong>' . __( '本地订单号' ) . ':</strong></p>';
            echo '<p>' . $order_extra_info->ref . '</p>';
            echo '<p><strong>' . __( '通道订单号' ) . ':</strong> ' . $order_extra_info->ordercode . '</p>';
        ?>
    </div>
<?php }

订单详情页

// 路径:wp-content/themes/razzi/functions.php
// 添加2列自定义标题 ,放在订单列的后面
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns){
    $reordered_columns = array();
    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key == 'order_number' ){
            $reordered_columns['custom_column1'] = __( '本地订单号','theme_domain');
            $reordered_columns['custom_column2'] = __( '上游订单号','theme_domain');
        }
    }
    return $reordered_columns;
}

//为列指定元数据
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id ){
    global $wpdb;
    $order_extra_info = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}superxpay_rapay_data WHERE  orderid = '".$post_id."'");
    switch ( $column ){
        case 'custom_column1' :
            if(!empty($order_extra_info))
                echo $order_extra_info->ref;
            else
                echo '<small><em>.</em></small>';
            break;
        case 'custom_column2' :
            if(!empty($order_extra_info))
                echo $order_extra_info->ordercode;
            else
                echo '<small><em>.</em></small>';
            break;
    }
}
0

评论 (0)

取消