I am building a custom theme and trying to create a "Cart" link which, when hovered over, will display a preview of the WooCommerce cart.
Using the following code from this post: Get cart item name, quantity all details woocommerce
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = wc_get_product( $values['data']->get_id() );
//product image
$getProductDetail = wc_get_product( $values['product_id'] );
echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
echo "<b>".$_product->get_title() .'</b> <br> Quantity: '.$values['quantity'].'<br>';
$price = get_post_meta($values['product_id'] , '_price', true);
echo " Price: ".$price."<br>";
/*Regular Price and Sale Price*/
echo "Regular Price: ".get_post_meta($values['product_id'] , '_regular_price', true)."<br>";
echo "Sale Price: ".get_post_meta($values['product_id'] , '_sale_price', true)."<br>";
}
?>
I have successfully managed to create a nice little display of the cart.
BUT - It is not showing the correct variation of the product which has been added to the cart. It is only showing the main featured image of the product, and not the image of the variation that has been added.
Can anyone tell me how to get and display the details of the specific product variations which have been added to the cart?