WC()->cart->get_cart() shows empty but not on cart page

I have a PHP script on a WooCommerce webserver that interfaces with an Android app I am developing. I mainly use it for logging into WordPress accounts and adding/removing products to the WooCommerce cart.

These functions work just fine:

function add_to_cart(){
    return WC()->cart->add_to_cart(

function remove_from_cart(){
        return 'Please specify cart_item_key';
    return 'Product removed from cart!';

This function also works, but it return an empty array…

function get_cart_contents(){
    return WC()->cart->get_cart();

However I know that the cart is not empty because when I add a product to the cart on the app it shows in the cart on the website. Is there a different function I should be calling? Am I forgetting to call something?

I’m on a learn-implement basis with PHP, constructive criticism welcome

Read more here: WC()->cart->get_cart() shows empty but not on cart page

Leave a Reply

Your email address will not be published. Required fields are marked *