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?

Read more here: How to display woocommerce cart count outside wordpress framework


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: