How to get the last cart item id and price Woocommerce in WordPress


Storing the ids and price in an array and using the end() function would be a solution in WordPress.


global $woocommerce;
$items = $woocommerce->cart->get_cart();
$ids = array();
foreach($items as $item => $values) {
        $_product = $values['data']->post;
        $ids[] = $_product->ID;

echo 'Last item = ' . end($ids);

$LastProductID = end($ids);

$LastProductPrice = wc_get_product( $LastProductID );


We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.