From 24403c244ee82e9c9a2868e7e41c78c03227c3ab Mon Sep 17 00:00:00 2001 From: Jason Kytros Date: Wed, 23 Oct 2024 09:39:49 +0300 Subject: [PATCH] [WC Tracker]: Track brands count (#52056) * [WC Tracker]: Track brands count * Add changefile(s) from automation for the following project(s): woocommerce * Handle case where the product_brand taxonomy doesn't exist. --------- Co-authored-by: github-actions --- .../changelog/52056-add-brands-count-tracking | 4 ++++ plugins/woocommerce/includes/class-wc-tracker.php | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 plugins/woocommerce/changelog/52056-add-brands-count-tracking diff --git a/plugins/woocommerce/changelog/52056-add-brands-count-tracking b/plugins/woocommerce/changelog/52056-add-brands-count-tracking new file mode 100644 index 00000000000..f9b2c0c19c5 --- /dev/null +++ b/plugins/woocommerce/changelog/52056-add-brands-count-tracking @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Added tracking for number of brands. \ No newline at end of file diff --git a/plugins/woocommerce/includes/class-wc-tracker.php b/plugins/woocommerce/includes/class-wc-tracker.php index fc535ac1cd3..ecea617d338 100644 --- a/plugins/woocommerce/includes/class-wc-tracker.php +++ b/plugins/woocommerce/includes/class-wc-tracker.php @@ -179,6 +179,7 @@ class WC_Tracker { $data['orders'] = self::get_orders(); $data['reviews'] = self::get_review_counts(); $data['categories'] = self::get_category_counts(); + $data['brands'] = self::get_brands_counts(); // Payment gateway info. $data['gateways'] = self::get_active_payment_gateways(); @@ -882,6 +883,18 @@ class WC_Tracker { return wp_count_terms( 'product_cat' ); } + /** + * Get the number of product brands. + * + * @return int + */ + private static function get_brands_counts() { + if ( ! taxonomy_exists( 'product_brand' ) ) { + return 0; + } + return wp_count_terms( 'product_brand' ); + } + /** * Get a list of all active payment gateways. *