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

https://wordpress.org/plugins/root-cookie/

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";
}
else{
    echo "Is not";
} ?> <Br />

<?php 
echo WC()->cart->get_cart_contents_count();
?>

Output:

Is logged in 
0

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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: