如何使新的WooCommerce管理订单列表列可搜索? [英] How to make a new WooCommerce admin order list column searchable?

查看:53
本文介绍了如何使新的WooCommerce管理订单列表列可搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Woocommerce Admin Order列表中添加了新列,但是现在我尝试使用右上角的搜索按钮使其可搜索.

I have added a new column to the Woocommerce Admin Order list, but now i try to make it searchable with the search button in the top right corner.

该列通常具有带有编号 $ numero_documento

The column usually has the invoice number with the variable $numero_documento

add_filter('manage_edit-shop_order_columns', 'boleta_o_factura' );
function boleta_o_factura( $order_columns ){
    $order_columns['boleta_factura'] = "Boleta o Factura Total_Pedido";
    return $order_columns;
}

add_action( 'manage_shop_order_posts_custom_column','misha_order_items_column_cnt' );
function misha_order_items_column_cnt( $colname ) {
    global $the_order; // the global order object
    $numero_documento = get_post_meta( $the_order->get_id(), 'Documento_numero', true );
    $pdf_link = get_post_meta( $the_order->get_id(), '_pdf_url', true );
    if( $colname == 'boleta_factura' ) {
        if( empty( $numero_documento )){
            echo get_post_meta($the_order->get_id(), 'error_logs_document', true);
        }
        else{
            echo "<a target='_blank' href=".$pdf_link.">Doc ".$numero_documento."</a><br>";
        }   
    echo $the_order->get_formatted_order_total();
    }
}

推荐答案

您可以使用 woocommerce_shop_order_search_fields 挂钩使其可搜索,只需添加正确的 meta_key

You can make it searchable with the woocommerce_shop_order_search_fields hook, just add the correct meta_key


注意:我已经略微简化了代码,因为我没有用于测试代码的相同字段(后元),但是这个概念有效

Note: I have simplified the code slightly, because I do not have the same fields (post meta) with which you test your code, but the concept works


注意:: manage_shop_order_posts_custom_column 包含 $ post_id 作为第二个参数,因此无需使用 global

Note: manage_shop_order_posts_custom_column contains as 2nd parameter the $post_id, so the use of global is not necessary

// Add a Header
function custom_shop_order_column( $columns ) {
    // Add new column
    $columns['boleta_factura'] = "Boleta o Factura Total_Pedido";

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

// Populate the Column
function custom_shop_order_list_column_content( $column, $post_id ) {
    // Compare
    if ( $column == 'boleta_factura' ) {
        $numero_documento = get_post_meta( $post_id, 'Documento_numero', true );

        if ( $numero_documento ) {
            echo $numero_documento;
        } else {
            echo 'my url';
        }
    }
}
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 2 );

// Make metakey searchable
function custom_shop_order_search_fields( $meta_keys ) {
    $meta_keys[] = 'Documento_numero';
    return $meta_keys;
}
add_filter( 'woocommerce_shop_order_search_fields', 'custom_shop_order_search_fields', 10, 1 );

这篇关于如何使新的WooCommerce管理订单列表列可搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆