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

#   Force Variants when adding to cart

##

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

Less More

- Posts: 8
- Thank you received: 3
-
-

12 years 8 months ago [\#147552](#147552) by [Billymb3](/forum/user/8027-billymb3 "View Billymb3's Profile")  *[Force Variants when adding to cart](/forum/26-product-category-display/866493-force-variants-when-adding-to-cart#147552 "-- url of the page with the problem -- :   girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt  -- HikaShop version -- : 2.2.1 -- Joomla version -- : 3.2 -- PHP version -- : 5.3.8 -- Browser(s) name and version -- : FIREFOX 27.0.1 -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  Hello-  I currently have our &quot;Add to Cart&quot; button hidden until the user chooses one of each of the products available characteristics.  We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events - 1. Add a class to the variants/characteristics that need to be selected. 2. set &quot;display block&quot; to a hidden div next to the variants with an error message.  End result would look like the error when adding a product here -   www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS  I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop&#95;button&#95;render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.  Any direction or suggestions would be great, thank you!  -Billy")* was created by *[Billymb3](/forum/user/8027-billymb3 "View Billymb3's Profile")*

-- url of the page with the problem -- : [ girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt](http://girlygeekclothing.com/women/womens-shirts/product/745-sudo-take-out-the-trash-womens-t-shirt)
-- HikaShop version -- : 2.2.1
-- Joomla version -- : 3.2
-- PHP version -- : 5.3.8
-- Browser(s) name and version -- : FIREFOX 27.0.1
-- Error-message(debug-mod must be tuned on) -- : Error_message

Hello-

I currently have our "Add to Cart" button hidden until the user chooses one of each of the products available characteristics.

We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events -
1. Add a class to the variants/characteristics that need to be selected.
2. set "display block" to a hidden div next to the variants with an error message.

End result would look like the error when adding a product here -
[ www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS](http://www.victoriassecret.com/clothing/all-tops-a/long-sleeve-v-neck-tee-vintage-tees?ProductID=168154&CatalogueType=OLS)

I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop_button_render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.

Any direction or suggestions would be great, thank you!

-Billy

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY0OTMtZm9yY2UtdmFyaWFudHMtd2hlbi1hZGRpbmctdG8tY2FydD90bXBsPW1hcmtkb3du) 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: 86541
- Thank you received: 14304
-
-

12 years 8 months ago [\#147564](#147564) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Force Variants when adding to cart](/forum/26-product-category-display/866493-force-variants-when-adding-to-cart#147564 "-- url of the page with the problem -- :   girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt  -- HikaShop version -- : 2.2.1 -- Joomla version -- : 3.2 -- PHP version -- : 5.3.8 -- Browser(s) name and version -- : FIREFOX 27.0.1 -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  Hello-  I currently have our &quot;Add to Cart&quot; button hidden until the user chooses one of each of the products available characteristics.  We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events - 1. Add a class to the variants/characteristics that need to be selected. 2. set &quot;display block&quot; to a hidden div next to the variants with an error message.  End result would look like the error when adding a product here -   www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS  I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop&#95;button&#95;render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.  Any direction or suggestions would be great, thank you!  -Billy")*

Hi,

The add to cart button is displayed by the file "quantity" of the view "product" that you can edit via the menu Display&gt;Views.
There you'll have several that line of code which calls the button display function: Code:

echo $this-&gt;cart-&gt;displayButton(JText::_('ADD_TO_CART'),'add',$this-&gt;params,$url,$this-&gt;ajax,'',$max,$min);

The $this-&gt;ajax variable contains the javascript code of the onclick trigger. If in that javascript you have a return false, it won't do the add to cart. And you can add any javascript in it. I recommend to first dump the content of the variable to see what's in it (it changes based on the options, etc) so that you can add your own javascript without breaking the add to cart function call.

The following user(s) said Thank You: [Billymb3](/forum/user/8027-billymb3 "View Billymb3's Profile")

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

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

Less More

- Posts: 8
- Thank you received: 3
-
-

12 years 8 months ago [\#148036](#148036) by [Billymb3](/forum/user/8027-billymb3 "View Billymb3's Profile")  Replied by *[Billymb3](/forum/user/8027-billymb3 "View Billymb3's Profile")* on topic *[Force Variants when adding to cart](/forum/26-product-category-display/866493-force-variants-when-adding-to-cart#148036 "-- url of the page with the problem -- :   girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt  -- HikaShop version -- : 2.2.1 -- Joomla version -- : 3.2 -- PHP version -- : 5.3.8 -- Browser(s) name and version -- : FIREFOX 27.0.1 -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  Hello-  I currently have our &quot;Add to Cart&quot; button hidden until the user chooses one of each of the products available characteristics.  We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events - 1. Add a class to the variants/characteristics that need to be selected. 2. set &quot;display block&quot; to a hidden div next to the variants with an error message.  End result would look like the error when adding a product here -   www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS  I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop&#95;button&#95;render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.  Any direction or suggestions would be great, thank you!  -Billy")*

Thank you so much for the direction Nicolas. I put the following code in the quantity view at line 20 and its working great. I am now just adding the error message warning the user to "choose a variant", and highlight the radio's and I am good to go.
Code:

$this-&gt;ajax = ' var chosenVariant = document.getElementById(hikashop_product_quantity_field_1); if (chosenVariant = \'hikashop_product_quantity_field_1\') { return false; } else { return hikashopModifyQuantity(\''.$this-&gt;row-&gt;product_id.'\',field,1,0,\'cart\','.$module_id.') }';

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

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

Less More

- Posts: 1
- Thank you received: 0
-

11 years 6 months ago -  8 years 6 months ago [\#201283](#201283) by [kasimody](/forum/user/36877-kasimody "View kasimody's Profile")  Replied by *[kasimody](/forum/user/36877-kasimody "View kasimody's Profile")* on topic *[Force Variants when adding to cart](/forum/26-product-category-display/866493-force-variants-when-adding-to-cart#201283 "-- url of the page with the problem -- :   girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt  -- HikaShop version -- : 2.2.1 -- Joomla version -- : 3.2 -- PHP version -- : 5.3.8 -- Browser(s) name and version -- : FIREFOX 27.0.1 -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  Hello-  I currently have our &quot;Add to Cart&quot; button hidden until the user chooses one of each of the products available characteristics.  We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events - 1. Add a class to the variants/characteristics that need to be selected. 2. set &quot;display block&quot; to a hidden div next to the variants with an error message.  End result would look like the error when adding a product here -   www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS  I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop&#95;button&#95;render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.  Any direction or suggestions would be great, thank you!  -Billy")*

-

Last edit: 8 years 6 months ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile"). Reason: remove spam

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY0OTMtZm9yY2UtdmFyaWFudHMtd2hlbi1hZGRpbmctdG8tY2FydD90bXBsPW1hcmtkb3du) 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: 86541
- Thank you received: 14304
-
-

11 years 6 months ago [\#201299](#201299) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Force Variants when adding to cart](/forum/26-product-category-display/866493-force-variants-when-adding-to-cart#201299 "-- url of the page with the problem -- :   girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt  -- HikaShop version -- : 2.2.1 -- Joomla version -- : 3.2 -- PHP version -- : 5.3.8 -- Browser(s) name and version -- : FIREFOX 27.0.1 -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  Hello-  I currently have our &quot;Add to Cart&quot; button hidden until the user chooses one of each of the products available characteristics.  We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events - 1. Add a class to the variants/characteristics that need to be selected. 2. set &quot;display block&quot; to a hidden div next to the variants with an error message.  End result would look like the error when adding a product here -   www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS  I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop&#95;button&#95;render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.  Any direction or suggestions would be great, thank you!  -Billy")*

Did you have any question kasimody ?

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

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

Less More

- Posts: 1
- Thank you received: 0
-
-

10 years 1 month ago [\#250422](#250422) by [DavidBoling](/forum/user/45065-davidboling "View DavidBoling's Profile")  Replied by *[DavidBoling](/forum/user/45065-davidboling "View DavidBoling's Profile")* on topic *[Force Variants when adding to cart](/forum/26-product-category-display/866493-force-variants-when-adding-to-cart#250422 "-- url of the page with the problem -- :   girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt  -- HikaShop version -- : 2.2.1 -- Joomla version -- : 3.2 -- PHP version -- : 5.3.8 -- Browser(s) name and version -- : FIREFOX 27.0.1 -- Error-message(debug-mod must be tuned on) -- : Error&#95;message  Hello-  I currently have our &quot;Add to Cart&quot; button hidden until the user chooses one of each of the products available characteristics.  We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events - 1. Add a class to the variants/characteristics that need to be selected. 2. set &quot;display block&quot; to a hidden div next to the variants with an error message.  End result would look like the error when adding a product here -   www.victoriassecret.com/clothing/all-top...54&amp;CatalogueType=OLS  I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop&#95;button&#95;render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.  Any direction or suggestions would be great, thank you!  -Billy")*

Nice collection! Thanks for the post.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY0OTMtZm9yY2UtdmFyaWFudHMtd2hlbi1hZGRpbmctdG8tY2FydD90bXBsPW1hcmtkb3du) 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.070 seconds

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