0
votes

I'm developing a theme for woocommerce plugin (2.0.12) in wordpress (3.5.1).

In my home page I've added featured products, recent products & top rated products through shortcode which are appearing fine.

Problem: The 'Add to Cart' buttons AJAX is not working. Instead of the AJAX call, the page reloads on clicking the 'Add to Cart' button of an individual product. I've added the cart.min.js in the page, but still the problem persists. It seems that the js variable woocommerce_meta is not getting loaded.

The url is:http://demo.pixelpoetics.net/ecommerce

Thank you in advance.

5

5 Answers

2
votes

Check if your 'Add to cart-button' has the following classes: .add_to_cart_button, .product_type_simple. Also check if the button has the dataAttr data-product_id. These items should be given, otherwise neither the add-to-cart.js will trigger the ajaxcall, nor will return a false, which prevents from loading a new page.

If your checking will show these lacks, try to edit the specific templates.

1
votes

Your cart is updating, but the number of products showed next to "Cart" in the cart button is not updating. I recommend you to use a plugin like "woocommerce dropdown cart widget" to integrate and show your cart easily.

0
votes

In functions.php, the woocommerce scripts are likely dequeued.

Remove any occurences like from functions.php

wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-cart' );
0
votes

Make sure that you have added <?php wp_footer(); ?> in footer.php of your custom theme.

-1
votes

I was having a similar problem to this and found this thread on my search for a solution. I did the age old test of changing themes and found that it was a problem with my theme not being 100% compatible with woocommerce. I found this article which explains a couple of ways to remedy this problem. http://chrislema.com/improving-the-woocommerce-add-to-cart-button/

I understand that this may not be the fix for this particular problem listed in this thread, but it may become useful to someone else looking for a solution. What fixed this for me was copying the page.php file inside my theme and replacing the "has_posts" loop with the following:

   //Create a copy of page.php and replace the "has posts" loop

   //I had this code in as the "has posts" loop
   <?php while ( have_posts() ) : the_post(); ?>
      <h5><?php echo do_shortcode(get_the_title()); ?></h5>
   <?php endwhile; // end of the loop. ?>

   //I replaced that loop with this
   <?php woocommerce_content(); ?>

I hope this helps someone else who is having trouble getting the add to cart button to work on the product page.

PS this same problem was preventing my Submit Review button from working.