Get all items in Cart Programmatically

Home Forums Legacy Support Support queries How-to & Troubleshooting Get all items in Cart Programmatically

Tagged: , ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #363183
    abumuhsin
    Spectator
    Hello, I am trying to use the woocommerce API WC()->cart->get_cart() to get all the items that have been added to the cart. unfortunately, iI keep getting the error Call to a member function get_cart() on null when I already have some courses in the cart. How can I access all the courses in the cart? and How do can I identify if a course is a gifted course? Thank you.
    #363433
    Anshuman Sahu
    Keymaster
    These articles might help : https://stackoverflow.com/questions/60580745/uncaught-error-call-to-a-member-function-get-cart-on-null https://stackoverflow.com/questions/64425146/avoid-error-call-to-a-member-function-get-cart-in-woocommerce-function Also a function exists check may also help : function_exists('WC')
    #363487
    abumuhsin
    Spectator
    function_exists('WC') returns true Using the code from stackoverflow I still get the error Fatal error: Uncaught Error: Call to a member function get_cart() on null in /var/web/staging/
    #363713
    Anshuman Sahu
    Keymaster
    Well in such a case you will have to contact the woocommerce itself as the erorr is not connetced to our theme or any of its plugins . you can also try if(method_exists(WC()->cart,'get_cart'))
Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Get all items in Cart Programmatically’ is closed to new replies.