在 WooCommerce 管理产品列表中添加税收 class 列
Add a tax class column to WooCommerce admin products list
此代码在管理产品列表页面的列中显示税务状态。但我需要显示税 class 我该如何显示它?
add_filter( 'manage_edit-product_columns', 'tax_status_product_column');
function tax_status_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_status'] = __( 'Tax status','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_status_product_column_content', 10, 2 );
function tax_status_product_column_content( $column, $post_id ){
if( $column == 'tax_status' ){
global $post, $product;
// Excluding variable and grouped products
if( is_a( $product, 'WC_Product' ) ) {
$args = array(
'taxable' => __( 'Taxable', 'woocommerce' ),
'shipping' => __( 'Shipping only', 'woocommerce' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' ),
);
echo $args[$product->get_tax_status()];
}
}
}
要在管理产品列表中显示产品税 class 列,请使用以下内容:
add_filter( 'manage_edit-product_columns', 'tax_class_product_column');
function tax_class_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_class'] = __( 'Tax class','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_class_product_column_content', 10, 2 );
function tax_class_product_column_content( $column, $post_id ){
if( $column == 'tax_class' ){
global $post, $product;
// Excluding variable and grouped products
if( is_a( $product, 'WC_Product' ) ) {
$args = wc_get_product_tax_class_options();
echo $args[$product->get_tax_class()];
}
}
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
此代码在管理产品列表页面的列中显示税务状态。但我需要显示税 class 我该如何显示它?
add_filter( 'manage_edit-product_columns', 'tax_status_product_column');
function tax_status_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_status'] = __( 'Tax status','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_status_product_column_content', 10, 2 );
function tax_status_product_column_content( $column, $post_id ){
if( $column == 'tax_status' ){
global $post, $product;
// Excluding variable and grouped products
if( is_a( $product, 'WC_Product' ) ) {
$args = array(
'taxable' => __( 'Taxable', 'woocommerce' ),
'shipping' => __( 'Shipping only', 'woocommerce' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' ),
);
echo $args[$product->get_tax_status()];
}
}
}
要在管理产品列表中显示产品税 class 列,请使用以下内容:
add_filter( 'manage_edit-product_columns', 'tax_class_product_column');
function tax_class_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_class'] = __( 'Tax class','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_class_product_column_content', 10, 2 );
function tax_class_product_column_content( $column, $post_id ){
if( $column == 'tax_class' ){
global $post, $product;
// Excluding variable and grouped products
if( is_a( $product, 'WC_Product' ) ) {
$args = wc_get_product_tax_class_options();
echo $args[$product->get_tax_class()];
}
}
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。