我想知道如何在结果显示$用户> billing_company销售订单的形式进行客户搜索时返回?理想的情况是正在考虑使用过滤器/行动挂钩,而不是修改类-WC-元箱订单data.php的核心文件
到目前为止,我能够搜索基于$用户> billing_company客户,结果将显示在编辑订单页面上,而不是增加新的订购页面($用户> billing_company不显示在打字时实时并点击搜索结果)
图片:https://i.stack.imgur.com/o4yfW.png
https://i.stack.imgur.com/pjfEM.png
修改后的代码:
esc_html__( '[%4$s] %1$s (#%2$s – %3$s)', 'woocommerce' )
$user->display_name,
absint( $user->ID ),
$user->user_email, $user->billing_company
从类-WC-元箱订单data.php原来的代码:
<?php
$user_string = '';
$user_id = '';
if ( $order->get_user_id() ) {
$user_id = absint( $order->get_user_id() );
$user = get_user_by( 'id', $user_id );
/* translators: 1: user display name 2: user ID 3: user email */
$user_string = sprintf(
esc_html__( '%1$s (#%2$s – %3$s)', 'woocommerce' ),
$user->display_name,
absint( $user->ID ),
$user->user_email
);
}
?>
<select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?></option>
</select>
<!--/email_off-->
</p>
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>
先感谢您!
下面的挂钩函数可以让你在不修改核心文件显示开票公司:
add_filter( 'gettext', 'change_admin_single_order_heading3', 10, 3 );
add_filter( 'ngettext', 'change_admin_single_order_heading3', 10, 3 );
function change_admin_single_order_heading3( $translated, $text, $domain ) {
global $pagenow, $theorder;
if ( is_admin() && $pagenow === 'post.php' && isset($_GET['post']) && get_post_type($_GET['post']) === 'shop_order' )
{
if( $text === '%1$s (#%2$s – %3$s)' && $domain === 'woocommerce' && $theorder->get_user_id() > 0 ){
// Get user meta billing company
if( $billing_company = get_user_meta( $theorder->get_user_id(), 'billing_company', true ) ) {
$translated = esc_html__( '['.$billing_company.'] %1$s (#%2$s – %3$s)', $domain );
}
}
}
return $translated;
}
代码放在您的活动子主题的function.php文件(或活动主题)。测试和工程。
但是,你将无法执行搜索时,作为搜索的选择与阿贾克斯拉来显示它...