Home › Forums › Basel support forum › Conflict ajax add to acrt with plugin
Conflict ajax add to acrt with plugin
- This topic has 21 replies, 2 voices, and was last updated 7 years ago by
Artem Temos.
-
AuthorPosts
-
March 11, 2018 at 4:50 pm #45236
despina.minaParticipantHello,
i use a plugin that creates an extra option inside the page for upload media files (it’s called “WooCommerce Upload Files”).
But when i activate Ajax add to cart option in theme settings,then is not possible to add the product in basket if i upload a file (only in products with variations).
I sent a ticket in plugin’s creator and i quote you his answer:
“I’ve performed some analysis and the issue you experience is related to theme you are using.
More in specific: your theme uses a custom ajax function to add the product to the cart and not the standard post method used by woocommerce product page template.
That Ajax function, once the add to cart button is clicked, sends the product id that has to be added to cart via the add-to-cart parameter (see the attached images). However when the plugin is active, for some reasons, it is sending other parameters but not the one containing the product id.
It seems then that the custom function used by the theme is not properly implemented and when a 3rd party plugin is adding some extra content to the product page, it stops working.
You should then contact the theme developer in order to fix it and make it to properly send the needed parameter even when the Upload Files plugin is active”
Can you please help me because i don’t want disable Ajax add to cart?
Thank youMarch 11, 2018 at 5:15 pm #45244
despina.minaParticipantUpdate:it seems that can’t add a simple product when i added a variable product with file uploaded.
Attachments:
You must be logged in to view attached files.March 11, 2018 at 6:09 pm #45263
despina.minaParticipantProducts
March 12, 2018 at 7:42 am #45305
Artem TemosKeymasterHello,
Our AJAX add to cart function is not aware of any extra fields that may be added by a lot of external plugins. As for the product ID parameter, so our theme takes the default WooCommerce form fields and sends them to AJAX handler. So seems that this plugin changes our theme and WooCommerce HTML structure and add its own fields. Anyway, it may require an additional customization both our theme and that plugin to make them works well with each other. Sorry, but it is out of our theme support scope.
Regards
March 12, 2018 at 10:10 am #45337
despina.minaParticipantThe problem, as reported in the previous email, is just that custom function you implemented is not taking its own field (in specific the add-to-cart parameter) and sending to your ajax handler.
You have just to fix your handler in order to properly retrieve that value before sending the parameter.No futher extra work is required.
The Product ID is not a custom parameter added by the plugin, the plugin doesn’t need to send any parameter via ajax through this function. That is the parameter you use to proper let your custom function to work.
I would appreciate it to help me with that,thank youMarch 12, 2018 at 10:34 am #45349
Artem TemosKeymasterThe product ID field is a part of the WooCommerce form https://gyazo.com/f5b14c8c1cbbba211d40d1ce8f5332ad
But it is missed when the plugin is activated
https://gyazo.com/ed890704fbc9bd9743a51df771b73cd1March 12, 2018 at 10:46 am #45367
despina.minaParticipantYes,this is the problem.
You can read again replies
#45236 ,attached images in #45244 and #45337.
The Product ID is not a custom parameter added by the plugin, the plugin doesn’t need to send any parameter via ajax through this function.March 12, 2018 at 10:50 am #45368
Artem TemosKeymasterWe meant that this parameter is added by WooCommerce, and should be there even if the plugin is activated.
March 12, 2018 at 11:44 am #45382
despina.minaParticipantYes,but the ajax functionality is added from your theme,not from Woocommerce or the plugin.
With storefront for.ex the plugin works fineMarch 12, 2018 at 1:32 pm #45407
Artem TemosKeymasterYes, and it requires this parameter to be presented. It works with other themes because they don’t have AJAX add to cart functionality. You can disable it in Theme Settings -> Product page and it will work as with all other themes as you expect.
March 12, 2018 at 1:41 pm #45412
despina.minaParticipanti know this,but i would like to have this functionality.The problem is that i can add a simple product even if I have not added any file
March 12, 2018 at 2:14 pm #45436
Artem TemosKeymasterYes, you can do this with simple products because that parameter exists there. And for variable products, it is removed. It is more plugin related problem. The AJAX handler can’t add the product to the shopping cart if doesn’t get its ID.
March 12, 2018 at 2:41 pm #45445
despina.minaParticipantSo,you don’t support me? Αt least tell me how it works this functionality for simple and variable products so as to say in plugin’s creator the way to fix it
March 12, 2018 at 2:43 pm #45446
Artem TemosKeymasterWe would be glad to help you but what can we do in this situation? Plugin rewrites the HTML structure and it is no longer compatible with the JS scripts. The code for this function is located in the file
js/functions.js
. Function name –addToCartAllTypes
.March 13, 2018 at 1:25 pm #45693
despina.minaParticipantHello,i found solution by changing the functions.js file in line 219:
$thisbutton = $form.find(‘button.single_add_to_cart_button’)
The code retrieves the value of the “add to cart” button using the right selector and not the generic .button selector.
Actually the plugin is fully compatible with standard WooCommerce product page template. It is the theme that is custom implementing the product page template adding an ajax function to manage the add to cart function.
The add to cart button is not altered by the plugin and the value of that html element (that represent the product id that your function should pass to your handler) can be easily retrieved with one line of jQuery code:jQuery(‘buton.single_add_to_cart_button”).val();
I believed it was your responsibility to support me in this…Have a nice day
March 13, 2018 at 2:05 pm #45702
Artem TemosKeymasterHello,
So the problem is in the jQuery selectors interception. We didn’t know that the plugin added their own buttons there as well. By default, WooCommerce plugin doesn’t have any extra buttons with the same class there so it was not necessary to use the selector that you use. In such cases, simpler selectors – better performance. Anyway, we are glad that you solved that problem. We will consider changing this in our theme core files.
Kind Regards
March 13, 2018 at 3:39 pm #45720
despina.minaParticipantWould you like me to send you the changes? So do you tell me if there’s anything wrong?
March 13, 2018 at 3:48 pm #45724
Artem TemosKeymasterDo you mean the part of the code you changed? If it works as you expected, then there is nothing wrong there.
March 13, 2018 at 5:03 pm #45741
despina.minaParticipantI mean if you want it for included in the next update
March 13, 2018 at 8:22 pm #45773
Artem TemosKeymasterYes, please, post it here so we can use it in the future.
March 13, 2018 at 9:42 pm #45788
despina.minaParticipantIs this
Attachments:
You must be logged in to view attached files.March 14, 2018 at 7:36 am #45837
Artem TemosKeymasterGreat, thank you.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register