So many times I needed to “play” with Cart contents in order to modify the default behaviour (such as removing a columns, hide the sale price to prices, hide an item, etc.).
There is a great PHP function that always helps – it’s called print_r and you can use this to “see” what’s inside the cart array, so that you can return certain information in a message for example.
A bit advanced, but as you grow your WooCommerce coding skills, you will use this a lot 🙂

PHP Snippet: Print WooCommerce Cart Array
/**
* @snippet See what is inside the Cart array - WooCommerce
* @how-to businessbloomer.com/woocommerce-customization
* @sourcecode https://fa8faab2-7736-467b-aa28-860b32869022.express.conves.io/?p=21941
* @author Rodolfo Melogli, Business Bloomer
* @compatible WC 2.6.14, WP 4.7.2, PHP 5.5.9
*/
add_action( 'woocommerce_before_cart', 'bbloomer_print_cart_array' );
function bbloomer_print_cart_array() {
$cart = WC()->cart->get_cart();
print_r($cart);
}









Thanks for this and others snippets for woocommerce Rodolf, helped a lot a new woocommerce coder to find a way through.
Excellent!
Hi Rodolfo! I read somewhere once that there’s a way to force line breaks to this array to make it easier to read, but I haven’t been able to find that snippet since – do you know it? Hope so! Oh and thanks for all that you do and share!!
Hey Billy, thanks for your comment! YES! Try with: