Latest Post

How to get last cart item id and price woocommerce

How to get last cart item id and price woocommerce

How to get last cart item id and price woocommerce


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

<?php

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 );

$LastProductPrice->get_price()


?>

No comments