Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save abidkakkur11/0eb2b885afc916383e16980cb20b0b5d to your computer and use it in GitHub Desktop.

Select an option

Save abidkakkur11/0eb2b885afc916383e16980cb20b0b5d to your computer and use it in GitHub Desktop.
Display Total products count including variations on the backend "All Products" pages on WooCommerce
<?php
// Show total product + variation count in WooCommerce Products dashboard
add_action( 'manage_posts_extra_tablenav', function( $which ) {
global $wpdb;
if ( $which === 'top' && get_current_screen()->id === 'edit-product' ) {
// Count published products
$products_count = $wpdb->get_var("
SELECT COUNT(*)
FROM {$wpdb->posts}
WHERE post_type = 'product'
AND post_status = 'publish'
");
// Count published product variations
$variations_count = $wpdb->get_var("
SELECT COUNT(*)
FROM {$wpdb->posts}
WHERE post_type = 'product_variation'
AND post_status = 'publish'
");
$total_count = $products_count + $variations_count;
echo '<div style="margin: 8px 0; padding: 8px; background: #f1f1f1; border: 1px solid #ddd;">';
echo '<strong>Total Products:</strong> ' . esc_html( $products_count ) . ' | ';
echo '<strong>Total Variations:</strong> ' . esc_html( $variations_count ) . ' | ';
echo '<strong>Combined Total:</strong> ' . esc_html( $total_count );
echo '</div>';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment