0 ? ' ' . number_format_i18n( $n ) : ''; }, $s ); } public static function counts() { $hit = get_transient( self::TRANSIENT ); if ( is_array( $hit ) && isset( $hit['products'] ) ) { return $hit; } global $wpdb; $out = array( 'products' => 0, 'orders' => 0, 'customers' => 0, 'brands' => 0, 'categories' => 0, 'sessions' => 0 ); if ( post_type_exists( 'product' ) ) { $p = wp_count_posts( 'product' ); $out['products'] = ( $p && isset( $p->publish ) ) ? (int) $p->publish : 0; } if ( function_exists( 'wc_orders_count' ) ) { $out['orders'] = (int) wc_orders_count( 'completed' ); } $tax = taxonomy_exists( 'product_brand' ) ? 'product_brand' : ( taxonomy_exists( 'pwb-brand' ) ? 'pwb-brand' : '' ); if ( '' !== $tax ) { $n = wp_count_terms( array( 'taxonomy' => $tax, 'hide_empty' => false ) ); $out['brands'] = is_wp_error( $n ) ? 0 : (int) $n; } if ( taxonomy_exists( 'product_cat' ) ) { $n = wp_count_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => false ) ); $out['categories'] = is_wp_error( $n ) ? 0 : (int) $n; } $out['customers'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value LIKE %s", $wpdb->prefix . 'capabilities', '%' . $wpdb->esc_like( '"customer"' ) . '%' ) ); $t = $wpdb->prefix . 'aieo_sessions'; if ( (string) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $t ) ) === $t ) { $out['sessions'] = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$t}" ); } set_transient( self::TRANSIENT, $out, 10 * MINUTE_IN_SECONDS ); return $out; } }