phpwordpresswoocommerceproductadmin

Display 'tax status' on WooCommerce admin product list


How can I go about displaying the product 'tax status' (ie. taxable, delivery only, none) on the product list of the admin page?

I've been trying to display products as 'In Stock/Out of Stock' and 'Taxable/Not Taxable' on the product list so that I can easily determine the status of products and make changes if necessary.

I figured out how to display the Stock Status on the product list, however, when I try the same with the 'tax status', it doesn't work. I got Stock Status to display by adding the following code to functions.php. How can I have the 'Tax Status' display?

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

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

Solution

  • The following will display a custom column for product tax status in admin product list:

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

    Code goes in function.php file of your active child theme (or active theme). Tested and work.

    Related: Add custom columns to admin products list in WooCommerce 3