I have added products on the homepage using the widget, how to enable ajax for add-to-cart button and wishlist button of product widgets.
2 Answers 2
To enable AJAX add to cart on home page, You need to add small JS code
create:
app/design/frontend/{Package}/{theme}/Magento_Theme/layout/cms_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="myaddto" template="Magento_Theme::myaddto.phtml"/>
</referenceContainer>
</body>
</page>
create:
app/design/frontend/{Package}/{theme}/Magento_Theme/templates/myaddto.phtml
<script type="text/x-magento-init">
{
"[data-role=tocart-form]": {
"catalogAddToCart": {}
}
}
</script>
Note: If you have any other custom phtml on home page, you can add above in that file as well!
-
How to update the "Add to Cart" text to "Show Now"?zus– zus2021年04月19日 14:23:11 +00:00Commented Apr 19, 2021 at 14:23
-
Based on template, you can update text.for example for new products
/vendor/magento/module-catalog/view/frontend/templates/product/widget/new/content/new_grid.phtml. OR just enable template path hind for phtmlPawan– Pawan2021年04月19日 14:28:58 +00:00Commented Apr 19, 2021 at 14:28 -
Path: app\design\frontend\Zero\my_theme\Magento_PageBuilder\templates\catalog\product\widget\content\carousel.phtml Code: Line Number : 11 codeshare.io/G7wJobzus– zus2021年04月19日 15:50:28 +00:00Commented Apr 19, 2021 at 15:50
-
After the update text is showing "Shop Now", After clicking the show now button again its changed to Add to Cart text, how to update my text permanently?zus– zus2021年04月19日 15:52:40 +00:00Commented Apr 19, 2021 at 15:52
You have to override addtocart.phtml file
app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/view/addtocart.phtml
Now Just Replace "bindSubmit": false to "bindSubmit": true
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"catalogAddToCart": {
"bindSubmit": false
}
}
}
</script>
To
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"catalogAddToCart": {
"bindSubmit": true
}
}
}
</script>
Now delete cache and page_cache folder or flush cache.
Note: Make sure you have to set No from Store->Configuration->Sales->Checkout->Shopping Cart->After Adding a Product Redirect to Shopping Cart to No
-
Path : app\design\frontend\Zero\my_theme\Magento_Catalog\templates\product\view\addtocart.phtml Code: codeshare.io/5zZlMW Not working, if i click add-to-cart page loading.zus– zus2021年04月19日 13:59:43 +00:00Commented Apr 19, 2021 at 13:59
Explore related questions
See similar questions with these tags.