我使用的代码在WooCommerce管理订单列表中添加一列,显示来自特定订单状态的客户订单。
问题是,有时当我刷新订单页面时,会发生一些事情,它会给我10/15/30这样的缓慢请求:
x1c 0d1x的数据
我使用的代码是这样的。有人知道问题可能来自哪里吗?
add_action('manage_shop_order_posts_custom_column', 'display_order_count_column');
function display_order_count_column($column) {
global $post;
if ($column === 'order_count') {
$customer_phone = get_post_meta($post->ID, '_billing_phone', true);
// Премахване на разстоянията от телефонния номер
$customer_phone = str_replace(' ', '', $customer_phone);
if (!empty($customer_phone)) {
$order_count = count(get_posts(array(
'post_type' => 'shop_order',
'post_status' => array('wc-completed', 'wc-order-rdy'),
'meta_key' => '_billing_phone',
'meta_value' => $customer_phone,
'posts_per_page' => -1,
)));
if ($order_count >= 2) {
echo '<a href="' . admin_url("edit.php?s=" . $customer_phone . "&post_status=all&post_type=shop_order&action=-1&m=0&_customer_user&paged=1&action2=-1") . '" class="Button_all_status" title="Числото показва броя на успешно завършените поръчки, които клиента има.">' . $order_count . '</a>';
} else {
echo '';
}
} else {
echo '';
}
}
if ($column === 'order_count') {
$customer_phone = get_post_meta($post->ID, '_billing_phone', true);
if (!empty($customer_phone)) {
$order_count = count(get_posts(array(
'post_type' => 'shop_order',
'post_status' => array('wc-on-hold', 'wc-processing', 'wc-order-rdy'),
'meta_key' => '_billing_phone',
'meta_value' => $customer_phone,
'posts_per_page' => -1,
)));
if ($order_count >= 2) {
echo '<a href="' . admin_url("edit.php?s=" . $customer_phone . "&post_status=all&post_type=shop_order&action=-1&m=0&_customer_user&paged=1&action2=-1") . '" class="Button_in_process" title="Числото показва броя на поръчките, които клиента има в обработка.">' . $order_count . '</a>';
} else {
echo '';
}
} else {
echo '';
}
}
if ($column === 'order_count') {
$customer_phone = get_post_meta($post->ID, '_billing_phone', true);
if (!empty($customer_phone)) {
$completed_processing_count = count(get_posts(array(
'post_type' => 'shop_order',
'post_status' => array('wc-completed', 'wc-processing', 'wc-order-rdy'),
'meta_key' => '_billing_phone',
'meta_value' => $customer_phone,
'posts_per_page' => -1,
)));
$cancelled_failed_count = count(get_posts(array(
'post_type' => 'shop_order',
'post_status' => 'wc-cancelleddonttake',
'meta_key' => '_billing_phone',
'meta_value' => $customer_phone,
'posts_per_page' => -1,
)));
if ($cancelled_failed_count > $completed_processing_count) {
echo '<a href="' . admin_url("edit.php?s=" . $customer_phone . "&post_status=all&post_type=shop_order&action=-1&m=0&_customer_user&paged=1&action2=-1") . '" class="Button_bad_client" title="Рисков клиент. Моля, проверете поръчките на клиента.Клиента има повече провалени от колкото изпълнени поръчки">' . $cancelled_failed_count . '</a>';
} else {
echo '';
}
} else {
echo '';
}
}
字符串
我不知道会有什么问题。
1条答案
按热度按时间7lrncoxx1#
你的代码是执行4重职位查询行时显示管理订单列表页面,所以它是正常的,你得到缓慢的请求...
相反,您可以使用一个独特的轻量级自定义SQL查询(按行),它将按订单状态为您提供给予客户订单计数组。
请尝试以下操作:
字符串
代码放在你的子主题的functions.php文件中(或插件中)。测试和工作。
对于其他读者,这里是缺少的功能,添加一个“计数”列到管理员WooCommerce订单列表:
型