基于Add columns to admin orders list in WooCommerce答案代码,我能够添加3个自定义列到管理订单列表:
- 账单电子邮件,
- 计费电话,
- 付款方式标题。
我的代码:
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();
}
}
如何将搜索字段与账单电子邮件、账单电话或付款方式标题一起使用?
1条答案
按热度按时间ycl3bljg1#
根据这个答案,以下内容将使管理员订单可通过以下方式进行搜索:
代码放在子主题的functions.php文件中(或插件中)。测试和作品。