Comments on: Woocommerce ajax add to cart tutorial on single/archive pages https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/ Boost the power of your Divi website Fri, 17 Nov 2023 12:30:39 +0000 hourly 1 https://wordpress.org/?v=6.5.4 By: kev https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-171096 Sun, 06 Jun 2021 19:50:24 +0000 https://diviengine.com/?p=1773#comment-171096 Getting an error Parse error: syntax error, unexpected ‘&’ in

on line:

error_log("Variation Product", 0);

Nobody else had that?

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-155732 Thu, 19 Nov 2020 09:39:37 +0000 https://diviengine.com/?p=1773#comment-155732 In reply to Paweł.

Not sure – might be conflict with WooCommerce ajax add to cart. The code works for us

]]>
By: Paweł https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-155729 Thu, 19 Nov 2020 08:34:01 +0000 https://diviengine.com/?p=1773#comment-155729 I have a problem. Some products add double. I can’t find a solution to this rpboelm. I need help

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-153672 Mon, 02 Nov 2020 08:53:00 +0000 https://diviengine.com/?p=1773#comment-153672 In reply to Harry.

Pleasure 😀

]]>
By: Harry https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-153626 Sun, 01 Nov 2020 12:51:19 +0000 https://diviengine.com/?p=1773#comment-153626 Easy to do and it works like a charm! Thank you!

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-152138 Mon, 19 Oct 2020 09:07:23 +0000 https://diviengine.com/?p=1773#comment-152138 In reply to Xavier.

Not sure, maybe there is JS conflict or something else. Sorry

]]>
By: Xavier https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-152116 Mon, 19 Oct 2020 07:24:09 +0000 https://diviengine.com/?p=1773#comment-152116 Hello, I added everything you are talking about to my theme, but it doesn’t work…

]]>
By: Arnold https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-118866 Mon, 24 Feb 2020 13:42:58 +0000 https://diviengine.com/?p=1773#comment-118866 In reply to Divi Engine.

I see,
Thanks

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-118794 Mon, 24 Feb 2020 10:31:15 +0000 https://diviengine.com/?p=1773#comment-118794 In reply to Arnold.

What do you mean, we have added this on the page – see under the title “The full javascript code you need to add is:”

]]>
By: Arnold https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-118322 Fri, 21 Feb 2020 12:32:04 +0000 https://diviengine.com/?p=1773#comment-118322 In reply to Divi Engine.

Hi,

Can you post again the full javascript code? I mean the final version.

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-52590 Mon, 03 Jun 2019 08:40:48 +0000 https://diviengine.com/?p=1773#comment-52590 In reply to http://canadianorderpharmacy.com/.

Thanks for the comment, there was an issue ages ago with this post but I sorted it.

Where can you see the text going off the screen?

]]>
By: http://canadianorderpharmacy.com/ https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-52511 Sun, 02 Jun 2019 17:37:49 +0000 https://diviengine.com/?p=1773#comment-52511 I don’t know if it’s just me or if perhaps everybody else encountering issues with your website. It appears like some of the written text in your content are running off the screen. Can somebody else please provide feedback and let me know if this is happening to them too? This could be a problem with my internet browser because I’ve had this happen before. Cheers

]]>
By: Jorge https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-48396 Fri, 17 May 2019 08:31:51 +0000 https://diviengine.com/?p=1773#comment-48396 In reply to Divi Engine.

I think the problem is that we do not know very well where to locate this section or that this section is not doing its job.

$variation_form = $( this ).closest( ‘.variations_form’ );
var product_id = $variation_form.find( ‘input[name=product_id]’ ).val();
var quantity = $variation_form.find( ‘input[name=quantity]’ ).val();
var var_id = $variation_form.find( ‘input[name=variation_id]’ ).val();

Can you say where we should exactly locate it to know if we are implementing it correctly?

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-48084 Thu, 16 May 2019 09:41:58 +0000 https://diviengine.com/?p=1773#comment-48084 In reply to Jorge.

Ya I am not sure – if there are no errors then I am not sure. You may need to contact your host and ask for the error log file (or you can find it on your server) – this might tell you what the problem is.

Not trying to sell our plugin but know it works with this so if you use Divi and can utilise the other features I would suggest using this as you know it will work.

]]>
By: Jorge https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-47970 Thu, 16 May 2019 07:29:56 +0000 https://diviengine.com/?p=1773#comment-47970 In reply to Divi Engine.

no type of error appears, only that the load wheel continues infinitely without adding the product to the cart.

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-47381 Tue, 14 May 2019 09:21:11 +0000 https://diviengine.com/?p=1773#comment-47381 In reply to Jorge.

What error are you getting?

]]>
By: Jorge https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-47360 Tue, 14 May 2019 09:04:58 +0000 https://diviengine.com/?p=1773#comment-47360 I have implemented my website with this code, but there seems to be an error. The products are not added to the cart with the new wordpress update. Can help us?

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8609 Mon, 03 Dec 2018 10:20:05 +0000 https://diviengine.com/?p=1773#comment-8609 In reply to Angel.

Hi Angel

Taken a quick look and seems the issue is here:

[javascript]
var product_id = $(this).parent().find(".product_id").val();
var quantity = $(this).parent().find(".qty").val();
[/javascript]

The issue is that it is looking for a input with the calss product_id and qty inside the parent div. This is not in the modal.

Try adding the html inputs inside the add to cart template inside WooCommerce.

Sorry I cannot be more helpful, this is beyond as you mention but this might help you along your way.

Thanks
Pete

]]>
By: Angel https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8608 Mon, 03 Dec 2018 10:00:38 +0000 https://diviengine.com/?p=1773#comment-8608 It all works now with no issues, thanks!

With my setup (https://www.mediatics-desa.com/desa/mako/delivery/) I’m getting a bad 404 request when I open a product in a modal and click the button. On variable products it works just fine, weirdly enough (like with the tee, “camiseta”).

I know this is beyond the scope of this very helpful post but if it doesn’t take more than a minute would you be so kind to check it out? I think this code snippet would be even more useful if it worked with shortcodes.

Thanks and sorry to bother you.

PS: Sorry for not replying to other messages… it doesn’t let me, for some reason.

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8605 Mon, 03 Dec 2018 08:33:00 +0000 https://diviengine.com/?p=1773#comment-8605 In reply to Angel.

Thanks, Angel, fixed those syntax errors – sorry – it is not copying across properly.

I am not sure how to get it to work with your setup, it should work as long as the HTML structure is similar which I would imagine it would be. Make sure the button has the class ajax_add_to_cart and you have the right HTML structure so that it can find the quantity and product ID.

Thanks!

]]>
By: Angel https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8603 Mon, 03 Dec 2018 07:55:08 +0000 https://diviengine.com/?p=1773#comment-8603 Sorry but replying isn’t working for me (the whole comments system is doing weird things). Anyway, it’s almost fixed now, only a couple of tings on lines 14 and 92.

By the way, is there any way to make this work with the product shortcode? I’m opening the products in a modal using that but AJAX doesn’t work there (this is the main reason I’m looking to “ajaxify” WooCommerce).

Thanks!

]]>
By: Fabian https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8511 Fri, 30 Nov 2018 15:54:55 +0000 https://diviengine.com/?p=1773#comment-8511 In reply to Divi Engine.

Hey,

there are still some formatting errors in your .js file.

Do I just need to copy the .js file into my assets folder and add your php markup into my functions.php?

Or is there anything else I am missing?

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8504 Fri, 30 Nov 2018 13:11:52 +0000 https://diviengine.com/?p=1773#comment-8504 In reply to Angel.

Hi Angel, thanks for letting me know – I have sorted this.

I realised I missed out the $thisbutton declaration – I have added it in the code now, please confirm 😀

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8503 Fri, 30 Nov 2018 13:02:31 +0000 https://diviengine.com/?p=1773#comment-8503 In reply to Fabian.

Hi Fabian, thanks for letting us know – can you check now?

]]>
By: Angel https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8498 Fri, 30 Nov 2018 12:41:32 +0000 https://diviengine.com/?p=1773#comment-8498 Hi,

So there’s some stuff polluted with & and other html encoded artifacts, plus, I’m getting a not defined in the console for $thisbutton (and it’s true, it’s not declared anywhere).

Thanks!

]]>
By: Fabian https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-8496 Fri, 30 Nov 2018 12:31:21 +0000 https://diviengine.com/?p=1773#comment-8496 In reply to Divi Engine.

Still formatting errors on this page. Please fix them. Thank you,

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-7088 Mon, 12 Nov 2018 08:27:08 +0000 https://diviengine.com/?p=1773#comment-7088 In reply to André.

Hi André.

I have taken a look and there are a few errors in the code due to the formatting. We are about to launch our new website this week and part of this is we are improving the way we show code snippets, I have updated the code there and is working.

Are you able to wait for the new site this week?

]]>
By: André https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-7043 Sat, 10 Nov 2018 08:28:42 +0000 https://diviengine.com/?p=1773#comment-7043 Hi Divi engine, Hope you well and thank you for this post. I am using divi and tryng to avoid plugins. This is then exactly what I need to display an add to cart button under all shown products.
QUestions:
Is this posts still up to date?
I have been all the process and it doesn’t seems to work for me. Any suggestion?
Thanks in advance.
ps: I am not a pro nor a coder, just a lot of interest 🙂

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-6004 Fri, 28 Sep 2018 08:01:11 +0000 https://diviengine.com/?p=1773#comment-6004 In reply to VISITOR.

Thanks for this. I am not sure how to get him to remove it. I have messaged him but don’t really know where I stand legally 😀

Appreciate the support!
Pete

]]>
By: VISITOR https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-6001 Thu, 27 Sep 2018 23:35:08 +0000 https://diviengine.com/?p=1773#comment-6001 I found this article https://quadmenu.com/add-to-cart-with-woocommerce-and-ajax-step-by-step/#comment-4045 apparently he just copy past your article, you should talk to him 😉

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-1273 Mon, 05 Feb 2018 08:59:34 +0000 https://diviengine.com/?p=1773#comment-1273 In reply to Roi.

Thanks for this, I will check this out! I have changed the code a bit on the plugin so will double check this all.

What do you mean there is a problem if the product is out of stock? Surely if it is out of stock you cant add it to cart?

Thanks for the comment!

]]>
By: Roi https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-1262 Sat, 03 Feb 2018 13:05:13 +0000 https://diviengine.com/?p=1773#comment-1262 just a minor bug – the second function should called bodycommerce_ajax_add_to_cart_woo_single_callback and not bodycommerce_ajax_add_to_cart_woo_callback

And there’s a problem if the product is out of stock

]]>
By: Divi Engine https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-890 Mon, 06 Nov 2017 16:51:32 +0000 https://diviengine.com/?p=1773#comment-890 In reply to christoffer.s.

Thanks for the comment. I realised that I left out bits of code on here. I have updated it now.

1) Variation not adding properly – I forgot to add the following:
– the two variables in the js code below line 13 ( I have added line 14 + 15 now)
– Getting the variation values from the post (I have added line 8 + 9) which looks for the variation ID and variation when they add it to cart (post)

2) I have had this issue on localhost before – are you using localhost to test?

3) I am not getting any errors – is it adding but producing an error or is it not working at all?

You can see the code working on our demo site – https://demo-bodycommerce.diviengine.com/product/beach-wear

Thanks again!

]]>
By: christoffer.s https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/#comment-888 Sun, 05 Nov 2017 10:49:13 +0000 https://diviengine.com/?p=1773#comment-888 Hi – excellent “plugin” i think, but I do believe there is a whole range of errors in the code and a major problem: when adding a variation to the cart it’s only adding the first variation from the dropdown, even if others are picked. As an example: if there are 2 variations, e.g. varying in color, called “red” and “blue” with price of $10 and $30, respectively, it will only add the first option ($10 “red”), even if blue is chosen.

Furthermore I seem to have found following errors:

When enqueuing script, you should use “.get_stylesheer_directory_uri() rather than simply get_stylesheet_directory() as this returns a 404 error (in my case at least).
Further, when inserting the hidden inputs you’ve written “$id = $product-<get_id();" which returned an error in my case, and replacing the "-” solved it. Not sure if that’s correct though as i’m not good at php.

In the js file I also got an error at line 36 since copying the JavaScript directly results in two line breaks, splitting it up after the “+ attributeTaxName + ‘” part.

In the PHP part i also got an error as the functions have the same name (2 times “bodycommerce_ajax_add_to_cart_woo_callback”)

]]>