in catalog page, there is a tool tip next to each product,once we click on it a popup, that contain attribute detail and add to cart button, should appear.
my question is how to add 'add to cart' button in this popup.
thank you

1 Answer 1


You can use this below piece of code in the popup phtml

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct');
      $addToCartUrl =  $listBlock->getAddToCartUrl($product); ?>
      <form data-role="tocart-form" action="<?php echo $addToCartUrl; ?>" method="post"> 
        <?php echo $block->getBlockHtml('formkey')?>
         <button type="submit" title="Add to Cart" class="action tocart primary">
           <span>Add to Cart</span>

Get $product using current registry.

  • Thank you for your answer, what if I should not use object manager?
    – sara ben
    Mar 8, 2022 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.