【发布时间】:2019-11-03 22:04:29
【问题描述】:
我正在构建一个自定义主题并尝试创建一个“购物车”链接,将鼠标悬停在该链接上时,将显示 WooCommerce 购物车的预览。
使用这篇文章中的以下代码: 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>";
}
?>
我已经成功地创建了一个漂亮的购物车小展示。
但是 - 它没有显示已添加到购物车的产品的正确变体。它只显示产品的主要特色图片,而不是已添加的变体图片。
谁能告诉我如何获取和显示已添加到购物车的特定产品变体的详细信息?
【问题讨论】:
标签: php wordpress woocommerce