基于Add columns to admin orders list in WooCommerce个应答代码,我能够向Admin Orders列表添加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();
}
}
如何将搜索字段与计费邮箱、计费电话或付款方式标题一起使用?