2013-12-12 46 views
2

我试图摆脱当用户将产品添加或在我woocommerce店得到一个信息消息重定向/重装的。我只是想在工具提示或叠加div中显示“添加到购物车”消息,并让它们继续购物,而不必重新转到商店。显示woocommerce消息,而无需刷新页面

AJAX添加到购物车启用

所以我的问题是: 我能做些什么,而不刷新整个页面显示此消息?

编辑:的人也许有用,我的继承人最终代码:

$('.add_to_cart_button, .single_add_to_cart_button').click(function(e) { 
       var produkt_id; 
       if ($(this).attr('data-product_id') == undefined) { 
        produkt_id = $('input[type=hidden]').val(); 
       } else { 
        produkt_id = $(this).attr('data-product_id'); 
       } 


       var amount; 
       if ($(this).hasClass('single_add_to_cart_button') == true) { 
        if ($('.qty').val() !== '1') { 
         amount = $('.qty').val(); 
        } 
        console.log(amount + ' single_add_to_cart_button'); 
       } 
       else { 
        amount = '1'; 
        console.log(amount + ' add_to_cart_button'); 
       } 




       function addToCart(produkt_id) { 
        $.ajax({ 
         type: 'POST', 
         url: '?add-to-cart=' + produkt_id, 
         data: {'product_id': produkt_id, 
          'quantity': amount}, 
         success: function(response, textStatus, jqXHR) { 
         // callback 

         }/*, 
         dataType: 'JSON'*/ 
        }); 
       } 
       e.preventDefault(); 
       addToCart(produkt_id); 
    }); 

回答

2

你的意思是这样的: 如果你做的功能“addedToChart”它会做一个Ajax和科瑞在页面顶部的消息

$(document).on('click','.add_to_cart_button',function(e) { 
    e.preventDefault(); 
    addedToCart($(this).data('product_id')); 
}); 
    function addedToCart(id){ 
     $.ajax({ 
      type: "POST", 
      url: "some.php", 
      data: { product_id: id}, 
      success: function(){ 
      $('body').prepend('<div style="position:fixed; height:20px; width:100%; background-color:red; text-align:center;">Added to chart</div>'); 
      } 
     }); 
    } 
+0

是啊这就是我的意思,但我该如何停止PHP $ _POST?或者它被禁用,因为用ajax帖子替换帖子?对不起,我的广告englisch –

+0

你的意思是你只需要没有ajax部分的消息? – Rickert

+0

不,我认为,ajax成功响应是必要的消息放出,但我的问题是,当我做添加到购物车部分超过ajax是PHP的帖子(刷新)禁用或做两个脚本火? –

相关问题