[Skip to main content](#vessel-content)

#   How to manually trigger add to cart function?

##

- **[pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")**
- [![pvukovic's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/76678-pvukovic "View pvukovic's Profile") Topic Author
- [ Offline](/forum/user/76678-pvukovic)

Less More

- Posts: 19
- Thank you received: 3
-
-

3 years 1 month ago [\#355882](#355882) by [pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")  *[How to manually trigger add to cart function?](/forum/26-product-category-display/907132-how-to-manually-trigger-add-to-cart-function#355882 "-- HikaShop version -- : 4.7.5 -- Joomla version -- : 4.3.4 -- PHP version -- : 8.0.27 -- Browser(s) name and version -- : Chrome  Hi,  we have a small number of products and we're using SP Page Builder to design richly formatted product pages that our marketing team can easily maintain.  For this purpose, we would like to trigger add to cart function manually when the user clicks &quot;Add to Cart&quot; button on this page, as we are no longer relying on native HikaShop product pages.  Is there a JavaScript API that would allow us to do this? For example, we would like to call a function that would contain a product id, quantity and any custom fields the user selected.  Thank you!")* was created by *[pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")*

-- HikaShop version -- : 4.7.5
-- Joomla version -- : 4.3.4
-- PHP version -- : 8.0.27
-- Browser(s) name and version -- : Chrome

Hi,

we have a small number of products and we're using SP Page Builder to design richly formatted product pages that our marketing team can easily maintain.

For this purpose, we would like to trigger add to cart function manually when the user clicks "Add to Cart" button on this page, as we are no longer relying on native HikaShop product pages.

Is there a JavaScript API that would allow us to do this? For example, we would like to call a function that would contain a product id, quantity and any custom fields the user selected.

Thank you!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDcxMzItaG93LXRvLW1hbnVhbGx5LXRyaWdnZXItYWRkLXRvLWNhcnQtZnVuY3Rpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

3 years 1 month ago [\#355891](#355891) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to manually trigger add to cart function?](/forum/26-product-category-display/907132-how-to-manually-trigger-add-to-cart-function#355891 "-- HikaShop version -- : 4.7.5 -- Joomla version -- : 4.3.4 -- PHP version -- : 8.0.27 -- Browser(s) name and version -- : Chrome  Hi,  we have a small number of products and we're using SP Page Builder to design richly formatted product pages that our marketing team can easily maintain.  For this purpose, we would like to trigger add to cart function manually when the user clicks &quot;Add to Cart&quot; button on this page, as we are no longer relying on native HikaShop product pages.  Is there a JavaScript API that would allow us to do this? For example, we would like to call a function that would contain a product id, quantity and any custom fields the user selected.  Thank you!")*

Hi,

What I would recommend is to use a content tag to let HikaShop display the add to cart button where you want it:
[ www.hikashop.com/support/documentation/1...-product-insert.html](https://www.hikashop.com/support/documentation/137-hikashop-product-insert.html)

HikaShop has an addToCart javascript function.
However, the parameters is has are not the ones you're expecting.
It's the function window.hikashop.addToCart in the file media/com_hikashop/js/hikashop.js
The first parametre of that function needs to be an element of the DOM (this usually is the add to cart button itself) with an attribute href with the add to cart URL, a data-addToCart attribute with the id of the product. You can leave the second and third parameters empty (null), and set the fourth one to a string of HTTP parameters like so: 'quantity=1&amp;xxx=yyy&amp;aaa=bbb'

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDcxMzItaG93LXRvLW1hbnVhbGx5LXRyaWdnZXItYWRkLXRvLWNhcnQtZnVuY3Rpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")**
- [![pvukovic's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/76678-pvukovic "View pvukovic's Profile") Topic Author
- [ Offline](/forum/user/76678-pvukovic)

Less More

- Posts: 19
- Thank you received: 3
-
-

3 years 1 month ago [\#355904](#355904) by [pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")  Replied by *[pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")* on topic *[How to manually trigger add to cart function?](/forum/26-product-category-display/907132-how-to-manually-trigger-add-to-cart-function#355904 "-- HikaShop version -- : 4.7.5 -- Joomla version -- : 4.3.4 -- PHP version -- : 8.0.27 -- Browser(s) name and version -- : Chrome  Hi,  we have a small number of products and we're using SP Page Builder to design richly formatted product pages that our marketing team can easily maintain.  For this purpose, we would like to trigger add to cart function manually when the user clicks &quot;Add to Cart&quot; button on this page, as we are no longer relying on native HikaShop product pages.  Is there a JavaScript API that would allow us to do this? For example, we would like to call a function that would contain a product id, quantity and any custom fields the user selected.  Thank you!")*

Thanks a lot, I will review and get back to you if I have any questions.

The following user(s) said Thank You: [Philip](/forum/user/34318-philip "View Philip's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDcxMzItaG93LXRvLW1hbnVhbGx5LXRyaWdnZXItYWRkLXRvLWNhcnQtZnVuY3Rpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")**
- [![pvukovic's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/76678-pvukovic "View pvukovic's Profile") Topic Author
- [ Offline](/forum/user/76678-pvukovic)

Less More

- Posts: 19
- Thank you received: 3
-
-

3 years 1 month ago [\#355974](#355974) by [pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")  Replied by *[pvukovic](/forum/user/76678-pvukovic "View pvukovic's Profile")* on topic *[How to manually trigger add to cart function?](/forum/26-product-category-display/907132-how-to-manually-trigger-add-to-cart-function#355974 "-- HikaShop version -- : 4.7.5 -- Joomla version -- : 4.3.4 -- PHP version -- : 8.0.27 -- Browser(s) name and version -- : Chrome  Hi,  we have a small number of products and we're using SP Page Builder to design richly formatted product pages that our marketing team can easily maintain.  For this purpose, we would like to trigger add to cart function manually when the user clicks &quot;Add to Cart&quot; button on this page, as we are no longer relying on native HikaShop product pages.  Is there a JavaScript API that would allow us to do this? For example, we would like to call a function that would contain a product id, quantity and any custom fields the user selected.  Thank you!")*

Hi, I was looking at this in more detail.

Ideally, I would use the product tag feature, but it seems it renders a "Choose Options" button in case the product has variants.

For example, here is the product page I have: [ prnt.sc/CIixiGLqgedR](https://prnt.sc/CIixiGLqgedR)

I want to be able to create an "Add to Cart" tag that specifies the value of the "CSWS Date" upfront, so the customer can pick the desired variant straight from the Add to cart button. Imagine having two buttons that say:

1. Add to Cart (Nov 13 &amp; 17)
2. Add to Cart (Nov 20 &amp; 24)

...each of which adds a specific variant to the cart.

Is this possible via tags? If not, what would be the advised approach for doing this via Javascript?

Thanks a lot for your help and support.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDcxMzItaG93LXRvLW1hbnVhbGx5LXRyaWdnZXItYWRkLXRvLWNhcnQtZnVuY3Rpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

3 years 1 month ago [\#355978](#355978) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to manually trigger add to cart function?](/forum/26-product-category-display/907132-how-to-manually-trigger-add-to-cart-function#355978 "-- HikaShop version -- : 4.7.5 -- Joomla version -- : 4.3.4 -- PHP version -- : 8.0.27 -- Browser(s) name and version -- : Chrome  Hi,  we have a small number of products and we're using SP Page Builder to design richly formatted product pages that our marketing team can easily maintain.  For this purpose, we would like to trigger add to cart function manually when the user clicks &quot;Add to Cart&quot; button on this page, as we are no longer relying on native HikaShop product pages.  Is there a JavaScript API that would allow us to do this? For example, we would like to call a function that would contain a product id, quantity and any custom fields the user selected.  Thank you!")*

Hi,

I don't see a problem with doing this with content tags.
However, of course, you need to provide the id of the variant, not the id of the product in your tag.
If you provide the id of the product with variants, the system will display a "choose options" button since it doesn't for which variant you're creating the button.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDcxMzItaG93LXRvLW1hbnVhbGx5LXRyaWdnZXItYWRkLXRvLWNhcnQtZnVuY3Rpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.048 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
