This is the function that you need to call and pass the product type that's registered in WordPress (by WooCommerce). It's 'product'.

$total_products_obj = wp_count_posts( 'product' );

 

This function call returns an object with multiple properties and you can decide what you need. The total number of published products or those saved as draft.

object(stdClass)#1011 (19) {
  ["publish"]=>
  string(2) "13"
  ["future"]=>
  int(0)
  ["draft"]=>
  int(0)
  ["pending"]=>
  int(0)
  ["private"]=>
  int(0)
  ["trash"]=>
  int(0)
  ["auto-draft"]=>
  int(0)
  ["inherit"]=>
  int(0)
  ["request-pending"]=>
  int(0)
  ["request-confirmed"]=>
  int(0)
  ["request-failed"]=>
  int(0)
  ["request-completed"]=>
  int(0)
  ["wc-pending"]=>
  int(0)
  ["wc-processing"]=>
  int(0)
  ["wc-on-hold"]=>
  int(0)
  ["wc-completed"]=>
  int(0)
  ["wc-cancelled"]=>
  int(0)
  ["wc-refunded"]=>
  int(0)
  ["wc-failed"]=>
  int(0)
}

 

To get the number of published products you need to access this property: $total_products_obj->publish

To get the number of draft products you need to access this property: $total_products_obj->draft

 

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer