How to get woocommerce cart id?

Member

by samara , in category: PHP CMS , 22 days ago

How to get woocommerce cart id?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 21 days ago

@samara 

To get the WooCommerce cart ID, you can use the following code snippet in your theme's functions.php file or in a custom plugin:

1
2
3
4
5
// Get WooCommerce cart ID
function get_woocommerce_cart_id( $cart_id ) {
    $cart_id = WC()->cart->generate_cart_id();
    return $cart_id;
}


You can then use the function get_woocommerce_cart_id() to retrieve the WooCommerce cart ID in your theme templates or anywhere else in your code.