如何使用 PHP 在 WooCommerce 中显示产品属性
我想以自定义方式显示整个购物车,因此我必须访问:
- 产品图片
- 产品标题
- 产品价格
- 产品属性
到目前为止,我设法显示除属性之外的所有内容。这是我到目前为止的工作代码。
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = wc_get_product( $values['data']->get_id() );
$getProductDetail = wc_get_product( $values['product_id'] );
echo $getProductDetail->get_image();
echo "<b>".$_product->get_title() .'</b> <br> Anzahl: '.$values['quantity'].'<br>';
$price = get_post_meta($values['product_id'] , '_price', true);
echo " Price: ".$price."<br>";
/*attributes*/
/* $available_variations = $_product->get_available_variations();
foreach ($available_variations as $key => $value) {
echo "$key $value";
}*/
}
?>
关于属性的最后一部分不起作用有人可以帮助我并告诉我如何访问购物车中每个产品的属性并将其显示在下面吗?
I want to display the entire shopping cart in a customized way, therefore I have to get access to the:
- Product Image
- Product Title
- Product Price
- Product Attributes
So far I managed to display everything but the attributes. This is my working code so far.
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = wc_get_product( $values['data']->get_id() );
$getProductDetail = wc_get_product( $values['product_id'] );
echo $getProductDetail->get_image();
echo "<b>".$_product->get_title() .'</b> <br> Anzahl: '.$values['quantity'].'<br>';
$price = get_post_meta($values['product_id'] , '_price', true);
echo " Price: ".$price."<br>";
/*attributes*/
/* $available_variations = $_product->get_available_variations();
foreach ($available_variations as $key => $value) {
echo "$key $value";
}*/
}
?>
The last part about the attributes is not working can someone assist me and tell me how to access the attributes of each product in the cart and display them underneath?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个代码
Try this code