2
我正試圖在woocommerce購物車頁面中獲取特定屬性值。 我在表格中製作了像這樣的自定義列。
Woocommerce在購物車頁面上獲取特定屬性值
<td class="product-color" data-title="<?php esc_attr_e('Color', 'woocommerce'); ?>">
<?php
echo apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($_product), $cart_item, $cart_item_key);
?>
</td>
<td class="product-size" data-title="<?php esc_attr_e('Size', 'woocommerce'); ?>">
<?php
echo apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($_product), $cart_item, $cart_item_key);
?>
</td>
<td class="product-price" data-title="<?php esc_attr_e('Price', 'woocommerce'); ?>">
<?php
echo apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($_product), $cart_item, $cart_item_key);
?>
</td>
當你看到所有的人都得到了產品價格。但我試圖獲得顏色和大小的屬性。 我搜索,發現這個:
foreach(wc_get_product_terms($product->id, 'pa_size') as $attribute_value){
// Outputting the attibute values one by one
echo $attribute_value . '<br>';
}
我試了一下這樣的:
<?php
echo apply_filters('woocommerce_cart_item_color', WC()->$product->get_attributes($_product),
$cart_item, $cart_item_key);
?>
,但沒有奏效
我最新的嘗試:
$test = $_product->get_attributes();
foreach($test['pa_size']['options'] as $size){
if ($size !== NULL) {
echo apply_filters('woocommerce_cart_item_price', $size , $cart_item, $cart_item_key);
var_dump($size);
} else {
echo "Not Specified";
}
}
,我得到這個結果INT(48)INT(47)
誰能幫我請。
我在這裏解決了這個問題: https://stackoverflow.com/questions/45520024/wordpress-woocommerce-product-attribute-return-key -not-value/45521680#45521680 –