How would I put the following code, for a certain shopping cart, just before the closing body tag in my WordPress site? In the footer? It seems to me that I would only want to call startcart() for product pages. Thanks very much.

However, if your JavaScript code is more substantial, or you wish to use built-in libraries such as jQuery, you should put the code in an external file, enqueue it properly using the wp_enqueue_script() function: