jeudi 24 mars 2016

Woocommerce Add Product with Link, redirect and Refresh Cart Page

I'm trying to setup a simple way of adding a Woocommerce product to the shopping cart by using an html a tag and after clicking on it redirect to the shopping cart page.

So far I can add the product to the cart but it only appears in the Cart if I force refresh the page. Basically the redirectToCart function is not refreshing the page.

            echo '<a class="btn btn-default" id="buy'.$image->ID.'" href="#">Order This!</a>
            <script>    
                $("#buy'.$image->ID.'").click(function(e) {
                  e.preventDefault();
                  addToCart(37);
                  redirectToCart("?page_id=27")
                  return false;
                 });    

                function addToCart(p_id) {
                  $.get("?post_type=product&add-to-cart=" + p_id, function() {  
                     // call back
                  });
                }

                function redirectToCart(cartPage) {
                    window.location.replace(cartPage);
                }
            </script>';

Can anyone help me out with this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire