0

By looking at this documentation https://docs.woothemes.com/wc-apidocs/class-WC_Cart.html it shows a lot of functions like

WC()->cart->check_cart_items();

which does work

Problem is when I try to print out array like in this case

$cart_contents

it just shows up as empty object

I did try to use

WC()->cart->init();

but result is the same. What could be the problem preventing from activating this object

4
  • What you want to get? Commented Dec 17, 2015 at 9:14
  • what code did you use to print it? Commented Dec 17, 2015 at 9:15
  • @MahaDev i want to get cart content array which should include item name and price Commented Dec 17, 2015 at 9:18
  • @Reigel print_r() function Commented Dec 17, 2015 at 9:18

1 Answer 1

1

You can use global woocommerce variable like this:

<?php 

    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    echo '<pre>';
    print_r($items);
    die;
?>
Sign up to request clarification or add additional context in comments.

1 Comment

WC() is the same as declaring global $woocommerce; and then calling $woocommerce;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.