Seems like what you need is NOT javascript at all.
If you are talking about OpenCart (as your title suggests), you need access to the total number of the products in your database (not in the page itself or DOM elements).
The ‘professional approach’ will be to extend your model and controller files with the correct methods,
but in case you are trying to avoid it (can’t really recommend it) this is what you need to do.
<div>
<?php
$query = $this->db->query("SELECT status FROM " . DB_PREFIX . "product WHERE status="1" ");
$products_count = $query->rows ? count($query->rows) : 0;
echo "Total products in store: " . $products_count;
?>
</div>
Again, since I’m a big fan of MVC structure, I’d recommend extending the controller and model to handle all the data, especially if you’re going to use this in multiple view files. This way, you’ll send the data to the view and all you’ll have to do in your code will be:
<div>
echo "Total products in store: " . $products_count;
</div>
Hope this helps!
3
solved A script to count the total number of products