【问题标题】:Display 'tax status' on WooCommerce admin product list在 WooCommerce 管理产品列表上显示“税务状态”
【发布时间】:2020-07-28 12:15:54
【问题描述】:

如何在管理页面的产品列表上显示产品“纳税状态”(即应税、仅送货、无)?

我一直在尝试在产品列表中将产品显示为“有货/缺货”和“应税/未税”,以便我可以轻松确定产品的状态并在必要时进行更改。

我想出了如何在产品列表上显示库存状态,但是,当我尝试使用“税务状态”时,它不起作用。我通过将以下代码添加到functions.php 来显示库存状态。如何显示“税务状态”?

add_filter( 'manage_edit-product_columns', 'product_column_arrange' );
function product_column_arrange( $product_columns ) {

    return array(
             ...
             'is_in_stock' => 'Stock',
             ...
    );
}

【问题讨论】:

    标签: php wordpress woocommerce product admin


    【解决方案1】:

    以下将在管理产品列表中显示产品税务状态的自定义列:

    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()];
            }
        }
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试和工作。

    相关:Add custom columns to admin products list in WooCommerce 3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多