如何使新的WooCommerce管理订单列表列可搜索? [英] How to make a new WooCommerce admin order list column searchable?
问题描述
我在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 correctmeta_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 ofglobal
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屋!