仅在WooCommerce管理员订单列表自定义列中显示特定订单状态的数据

用户名

我在WooCoomerce管理订单列表中有一个自定义列,用于显示客户注释。

如果订单处于特定的自定义状态,我只想在订单列表中显示注释wc-autoquote

是否可以针对所有其他订单状态将其过滤掉?

我的自定义列的代码:

add_filter('manage_edit-shop_order_columns', 'add_customer_note_column_header');
function add_customer_note_column_header($columns) {
    $new_columns = (is_array($columns)) ? $columns : array();

    $new_columns['order_customer_note'] = 'Customer Notes';

    return $new_columns;
}

add_action('admin_print_styles', 'add_customer_note_column_style');
function add_customer_note_column_style() {
    $css = '.widefat .column-order_customer_note { width: 15%; }';
    wp_add_inline_style('woocommerce_admin_styles', $css);
}


add_action('manage_shop_order_posts_custom_column', 'add_customer_note_column_content');
function add_customer_note_column_content($column) {
    global $post, $the_order;

    if(empty($the_order) || $the_order->get_id() != $post->ID) {
    $the_order = wc_get_order($post->ID);
    }

    $customer_note = $the_order->get_customer_note();
    if($column == 'order_customer_note') {
    echo('<span class="order-customer-note">' . $customer_note . '</span>');
}
7uc1f3r

您可以在指定状态时使用以下内容

// If has order status
if ( $order->has_status( 'MY STATUS' ) ) {...

所以你得到

// Add a Header
function filter_manage_edit_shop_order_columns( $columns ) {
    // Add new column
    $columns['order_customer_note'] = __( 'Customer Notes', 'woocommerce' );

    return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'filter_manage_edit_shop_order_columns', 10, 1 );

// Populate the Column
function action_manage_shop_order_posts_custom_column( $column, $post_id ) {
    // Compare
    if ( $column == 'order_customer_note' ) {
        // Get order
        $order = wc_get_order( $post_id );
    
        // Has order status
        if ( $order->has_status( 'autoquote' ) ) {
            // Get customer note
            $customer_note = $order->get_customer_note();
            
            // NOT empty
            if ( ! empty ( $customer_note ) ) {
                echo '<span class="order-customer-note">' . $customer_note . '</span>';
            }
        }
    }
}
add_action( 'manage_shop_order_posts_custom_column' , 'action_manage_shop_order_posts_custom_column', 10, 2 );

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Woocommerce管理员订单列表自定义列中显示结帐字段值

在Woocommerce管理员订单列表自定义列中显示用户名

Woocommerce 3.3管理员订单列表中的自定义订单状态背景按钮颜色

在WooCommerce管理员订单列表中以批量操作添加自定义取消订单状态

在Woocommerce管理员订单列表“订单”现有列中添加自定义字段

在Woocommerce管理订单列表中显示具有“全部”自定义状态的订单

将自定义订单状态添加到WooCommerce管理员订单列表中的过滤器菜单

在Woocommerce管理员订单列表上处理多个自定义批量操作

在 WooCommerce 管理订单列表的自定义列中显示私人和客户管理注释

WooCommerce 管理订单列表中自定义订单状态的操作按钮问题

在WooCommerce订单管理员列表上显示带有自定义用户元的自定义列

在 WooCommerce 管理订单列表的自定义列中显示每个订单项目的库存数量

在 WooCommerce 订单列表中显示 Dokan 自定义订单元数据

在Woocommerce管理员订单列表中显示带有作者和日期的订单注释

在WooCommerce管理员订单列表中显示每个订单的变体名称

Woocommerce在管理员订单详细信息上显示自定义字段数据

在Woocommerce管理员订单预览上显示自定义数据

在帐单地址后以WooCommerce管理员订单显示自定义元数据

在Woocommerce管理员,订单和电子邮件中显示自定义付款字段

单击以在WooCommerce管理订单列表中显示文本时隐藏自定义操作按钮

在Woocommerce管理员订单编辑页面中以编程方式添加自定义订单注释

在Woocommerce管理订单列表中添加可排序的自定义列

自定义操作按钮进入WooCommerce管理订单列表上的自定义列

仅在WooCommerce管理订单上显示自定义订单项目元数据

如何在WooCommerce管理员单笔订单中显示自定义结帐账单字段

在WooCommerce管理员订单页面上将产品自定义字段显示为订单项元

在WooCommerce管理员快速订单预览中自定义内容

在WooCommerce订单管理员中搜索自定义字段

Woocommerce管理员编辑订单页面常规部分中的自定义可编辑字段