This question already has an answer here:

I am creating an extension for adding a free product Y to cart when adding product X. I don't want to add product Y to cart if the user trying to add product Y itself. Can anyone suggest a solution for me??? (I tried to stop the product from adding to cart, but it is not working). Thanks

marked as duplicate by Raphael at Digital Pianism, Rakesh Jesadiya, Amit Bera, brentwpeterson, Fabian Blechschmidt Sep 23 '16 at 7:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What if you make product Y "not visible individually"? If it's only added automatically, you don't need the product page, do you? – Fabian Schmengler Sep 21 '16 at 8:20
  • You are right @fschmengler. But product Y is selected by the user in admin side. – Keerthana Sep 28 '16 at 6:21
  • I'm not sure if I understand. If you edit the question and explain the process in detail, it could be reopened. – Fabian Schmengler Sep 28 '16 at 6:32

Browse other questions tagged or ask your own question.