Ajaxify header cart items count in Woocommerce

前端 未结 3 395
臣服心动
臣服心动 2020-12-03 16:11

I\'m creating a custom woocommerce integrated theme for wordpress.

I have a blob on the top that displays the total number of items in the cart, I want to update thi

3条回答
  •  青春惊慌失措
    2020-12-03 17:03

    I have not used woocommerce before but one pretty simple option when you say in your post:

    When I visit this page it echos the current item totals, but I cant get this data from JQuery

    ...would be to use a user-sided JavaScript variable for the display, and then just call the PHP update methods for adding items to your cart using AJAX (which I do not show below because you have not provided that code).

    cart->get_cart_contents_count()
        $woocommerce = 59;
    ?>
    
    
    
    
    
    

    You can copy and test this snippet on: http://phpfiddle.org/

    Basically in the above code, I set the PHP value as a paragraph text on page load and then read that value into a JS variable to mess around with the data on the client side of the application and then I update the display text as needed.

提交回复
热议问题