在 Woocommerce 订单页面添加使用电子邮件搜索

问题描述 投票:0回答:1

我对之前的其他问题有疑问:将列添加到 WooCommerce 中的管理订单列表

与此问题相关的代码:

add_filter( 'manage_edit-shop_order_columns', 'add_custom_columns_to_admin_orders', 20);
function add_custom_columns_to_admin_orders( $columns ) {
    $new_columns = array();
    foreach ( $columns as $column_name => $column_info ) {
        $new_columns[ $column_name ] = $column_info;

        if ( 'order_total' === $column_name ) {
            $new_columns['order_email'] = __( 'Email Address', 'my-textdomain' );
            $new_columns['order_customers_phone'] = __( 'Customers Phone', 'my-textdomain' );
            $new_columns['order_payment'] = __( 'Payment Method', 'my-textdomain' );
        }
    }
    return $new_columns;
}


add_action( 'manage_shop_order_posts_custom_column', 'custom_columns_content_in_admin_orders' );
function custom_columns_content_in_admin_orders( $column ) {
    global $post, $the_order;
    if ( 'order_email' === $column ) {
        if ( $the_order->has_status( array('completed') ) ) {
            $email_address = $the_order->get_billing_email();
            echo '<span class="order_complete"> '.$email_address.' </span>';
        } else {
            echo '<span class="order_not_complete">This Order is Not Completed!</span>';
        }
    }
    
    if ( 'order_customers_phone' === $column ) {
        echo '<label for="billing_phone" class="label-billing-email">Customer Phone Number:  </label>';
        echo '<input type="text" name="billing_phone" value="' . $the_order->get_billing_phone() . '" readonly />';
    }
    
    if ( 'order_payment' === $column ) {
        echo $the_order->get_payment_method_title();
    }
}

是否可以添加搜索字段或使用此照片中的搜索字段(Serach Orders)来搜索我们添加的项目(Title1 和 Title1)的值? (可以过滤表格的哪一列来搜索,例如 Title1 或 Title2 或其他列)

php wordpress woocommerce metadata orders
1个回答
0
投票

基于此答案,以下内容将使管理订单可通过以下方式搜索:

  • 帐单电子邮件,
  • 计费电话,
  • 或付款方式标题。
add_filter( 'woocommerce_shop_order_search_fields', 'extending_admin_orders_search_field', 10, 1 );
function extending_admin_orders_search_field( $meta_keys ){
    $meta_keys[] = '_billing_email';
    $meta_keys[] = '_billing_phone';
    $meta_keys[] = '_payment_method_title';

    return $meta_keys;
}

代码位于子主题的functions.php 文件中(或插件中)。已测试并有效。

© www.soinside.com 2019 - 2024. All rights reserved.