Sorry for my late response. This is the function:
function fn_get_category_product_count($category_id) { $count = db_get_field('select count(product_id) from ?:products_categories p inner join ?:categories c on p.category_id = c.category_id where c.id_path like ?s', '%' . $category_id . '%');