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.
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')
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/
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'))