Display woocommerce cart total outside WordPress

so I followed this to try and get data from WordPress to display outside the wordpress directory (n.b. I also needed to install the root cookie plugin):

How to use woocommerce functions outside of wordpress


Anyway, I’m trying to display the cart count, but keep getting “0” even though the cart has items:

<?php include ($_SERVER['DOCUMENT_ROOT']."/store/wp-load.php")?> 

<?php if (is_user_logged_in()){
    echo "Is logged in";
    echo "Is not";
} ?> <Br />

echo WC()->cart->get_cart_contents_count();


Is logged in 

Any ideas what I’m doing wrong?

N.B. the WordPress API is not suitable for use here. As for cookies, I am using root cookie to change the path from /store to / which works fine for session data but the Woocommerce cookies are still stuck with the path /.

Read more here: Display woocommerce cart total outside WordPress

Leave a Reply

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