How to add a simple WooCommerce product list to the WordPress dashboard

By default WooCommerce doesn’t come with an easy way to show a simple product list in the WordPress dashboard. Even though there is of course the product post type overview, there is only few information of each product you can see at first glance. If you want to see the stock or if a product is missing a product image, you’ll have to click on a specific product and scroll to the information you need. This can be time consuming… But whats even worse: There is no way to see each variation of a variable product, without clicking into it.

A few weeks ago I’ve built a shortcode for a custom product slider. The slider showes products based on the product IDs my clients add to the shortcode, so it looked sth like this [product-slider product-ids=”15, 16, 20, 48, 50″]. But the problem was, that my clients had no easy way to find out the IDs of product variations, so they only could add the whole variable product to the slider. Because of this I wrote a simple code snippet, which adds a new page to the WordPress backend and show them a list of products, product variations and some product attributes they were interested in.

If you’re also interested in such list, just add this to your (child-) themes functions.php:

/* ADD PRODUCT LIST PAGE TO WP DASHBOARD */ 
if ( class_exists( 'WooCommerce' ) ): 

  add_action( 'admin_menu', 'tk_wp_dashboard_products_new_page', 9999 ); 

  function tk_wp_dashboard_products_new_page() { 
    
    // Add new dashboard page 
    add_submenu_page( 
      'edit.php?post_type=product', 
      'Product List', 
      'Product List', 
      'edit_products', 
      'product-list', 
      'tk_wp_dashboard_products_new_page_callback', 
      9999 
    ); 
  
  } 

  function tk_wp_dashboard_products_new_page_callback() { 
    
    // Query args 
    $query = new WC_Product_Query( 
      array( 
        'orderby' => 'title', 
        'order' => 'ASC', 
        'limit' => -1, 
      ) 
    ); 
    
    $products = $query->get_products(); 
    
    echo '<div class="wrap"><h1>Produktliste</h1>'; 

      if($products): 

        echo '<table>'; 
          echo '<tr>'; 
            echo '<th>' . __("Name", "tk") . '</th>'; 
            echo '<th>' . __("ID", "tk") . '</th>'; 
            echo '<th>' . __("Parent ID", "tk") . '</th>'; 
            echo '<th>' . __("Type", "tk") . '</th>'; 
            echo '<th>' . __("SKU", "tk") . '</th>'; 
            echo '<th>' . __("Price", "tk") . '</th>'; 
            echo '<th>' . __("Stock Quantity", "tk") . '</th>'; 
            echo '<th>' . __("Image ID", "tk") . '</th>'; 
            echo '<th>' . __("Weight", "tk") . '</th>'; 
          echo '</tr>'; 
          
          foreach( $products as $product ): 
            
          echo '<tr>'; 
            echo '<td>' . $product->get_name() . '</td>'; 
            echo '<td>' . $product->get_ID() . '</td>'; 
            echo '<td>' . $product->get_parent_ID() . '</td>'; 
            echo '<td>' . $product->get_type() . '</td>'; 
            echo '<td>' . $product->get_sku() . '</td>'; 
            echo '<td>' . $product->get_price() . '</td>'; 
            echo '<td>' . $product->get_stock_quantity() . '</td>'; 
            echo '<td>' . $product->get_image_id() . '</td>'; 
            echo '<td>' . $product->get_weight() . '</td>'; 
          echo '</tr>'; 
          
          if( $product->get_type() == 'variable'): 

            $variationIDs = $product->get_children(); 
            
            foreach( $variationIDs as $variationID ): 

              $variation = wc_get_product( $variationID ); 

              echo '<tr class="child">'; 
                echo '<td>' . $variation->get_name() . '</td>'; 
                echo '<td>' . $variation->get_ID() . '</td>'; 
                echo '<td>' . $variation->get_parent_ID() . '</td>'; 
                echo '<td>' . $variation->get_type() . '</td>'; 
                echo '<td>' . $variation->get_sku() . '</td>'; 
                echo '<td>' . $variation->get_price() . '</td>'; 
                echo '<td>' . $variation->get_stock_quantity() . '</td>'; 
                echo '<td>' . $variation->get_image_id() . '</td>'; 
                echo '<td>' . $variation->get_weight() . '</td>'; 
              echo '</tr>'; 

            endforeach;
          endif;
          endforeach; 
        
        echo '</table>';

      endif; 

    echo '</div>'; 
    
    echo '<style> 
      table { border-collapse: collapse; } 
      table, th, td { border: 1px solid black; text-align: left; padding: 5px; } 
      tr.child > td:first-child { padding-left: 30px; } 
    </style> '; 
  } 
endif;

 

If you have more than 200 products I’d recommend to add some pagination and maybe also a filter. But for a shop with only a few products I think this list can be really useful for you and your clients.

Leave a Comment