Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.
For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email firstname.lastname@example.org.
I am trying to add a product to the cart of the current user (logged in or not) using the code below. But then, when I go to the shopping cart to see if the product was added, the page says that the cart is empty.
I would advise you the Add Free Product To Cart Magento module that extends native Magento functionality with an ability of automatic product adding to the cart. An item appears in the shopping cart based on set criteria of the created rule.
You can give your client a product for free or suggest getting it with a specified discount. The information with the offer appears in a pop-up window or the product is added to the cart without any notice, so your clients will be in a daze after viewing the real ability of getting one more product absolutely for free.