WordPress.org

Forums

WooCommerce - excelling eCommerce
Update minicart after adding product with ajax button (2 posts)

  1. alvaron
    Member
    Posted 2 years ago #

    I'm using the code bellow to add a product with quantity to cart via ajax

    function addToCart(p_id,q_td) {
                jQuery.ajax({
                  type: 'POST',
                  url: '?post_type=product&add-to-cart='+p_id,
                  data: { 'product_id':  p_id,
                                'quantity': q_td},
                  success: function(response, textStatus, jqXHR){
    
                        console.log("Product added");
                    }
                  //dataType: 'JSON'
                });
            }
            jQuery('#buybtn').click(function(e) {
              e.preventDefault();
              addToCart(<?php echo $post->ID;?>,jQuery("#qtd").val());
              return false;
            });

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    What I need is to update minicart on sucess

    How can do it? The link bellow gives a clue, but how can I put "add_to_cart_fragments" to work on ajax?

    http://wcdocs.woothemes.com/snippets/show-cart-contents-total/

    http://wordpress.org/extend/plugins/woocommerce/

  2. DesignsAndCode
    Member
    Posted 1 year ago #

    Hey there did you ever figure out the solution? I'm stuck exactly where you are!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic