$label) { $new[$key] = $label; if ($key === 'title') { $new['product_price'] = __('价格', 'aksrt'); $new['product_stock'] = __('库存', 'aksrt'); $new['product_sales'] = __('销量', 'aksrt'); $new['product_stats'] = __('综合数据', 'aksrt'); $new['product_author_name'] = __('商家', 'aksrt'); $new['product_discount'] = __('优惠活动', 'aksrt'); } } return $new; } public function render_product_column(string $column, int $post_id): void { switch ($column) { case 'product_price': $price = get_post_meta($post_id, '_aksrt_price', true); echo esc_html(number_format_i18n((float) $price, 2)); break; case 'product_stock': $stock = get_post_meta($post_id, '_aksrt_stock', true); $stock_type = get_post_meta($post_id, '_aksrt_stock_type', true); if ($stock_type === 'opts') { echo esc_html__('按选项', 'aksrt'); } elseif ((int) $stock === -1) { echo esc_html__('无限', 'aksrt'); } else { echo esc_html((string) (int) $stock); } break; case 'product_sales': echo esc_html((string) (int) get_post_meta($post_id, '_aksrt_sales', true)); break; case 'product_stats': $views = (int) get_post_meta($post_id, '_aksrt_views', true); $fav = (int) get_post_meta($post_id, '_aksrt_favorite_count', true); printf( esc_html__('阅读 %1$d / 收藏 %2$d', 'aksrt'), $views, $fav ); break; case 'product_author_name': $post = get_post($post_id); if ($post) { $author = get_userdata($post->post_author); echo esc_html($author ? $author->display_name : '—'); } break; case 'product_discount': $terms = wp_get_object_terms($post_id, 'shop_discount', ['fields' => 'all']); if (!is_wp_error($terms) && !empty($terms)) { $term_ids = wp_list_pluck($terms, 'term_id'); $names = wp_list_pluck($terms, 'name'); echo ''; echo esc_html(implode(', ', $names)); } else { echo '—'; } break; } } public function sortable_product_columns(array $columns): array { $columns['product_sales'] = 'product_sales'; return $columns; } public function render_product_quick_edit(string $column_name, string $post_type): void { if ($column_name !== 'product_discount' || $post_type !== 'aksrt_product') { return; } wp_nonce_field('aksrt_product_quick_edit', 'aksrt_product_qe_nonce'); $discounts = get_terms([ 'taxonomy' => 'shop_discount', 'hide_empty' => false, ]); ?>

0 && term_exists($term_id, 'shop_discount')) { wp_set_object_terms($post_id, [$term_id], 'shop_discount'); } } } public function product_quick_edit_script(): void { $screen = get_current_screen(); if (!$screen || $screen->post_type !== 'aksrt_product') { return; } ?>