When the Magento 2 installation runs on both the main domain and the subdomain, you’ll notice that the ‘ Add to cart ‘ process doesn’t work on the subdomain (both the domains are open in the same browser).
This is a common issue with all the Magento 2 stores as the subdomain hosts the development or staging website.
We traced this problem and here’s the solution to add-to cart issue on the subdomain:
The issue occurs due to a conflict of PHP session cookie named “PHPSESSID”. The subdomain starts reading main domain’s cookie when both are open in the same browser.
We changed the PHP session name on the subdomain by adding the code given below at the beginning of Magento’s index.php file:
You can replace the text ‘rcM2DEMO’ with any unique string you like. And you’re done!