I'm trying to get specific attribute value in the woocommerce cart page.
I made custom columns in the table like those.
<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>
AS you see all of them get the product price. but I'm trying to get attribute of color and size.
I searched and found this :
foreach( wc_get_product_terms( $product->id, 'pa_size' ) as $attribute_value ){
// Outputting the attibute values one by one
echo $attribute_value . '<br>';
}
I tried it like that :
<?php
echo apply_filters( 'woocommerce_cart_item_color', WC()->$product->get_attributes( $_product ),
$cart_item, $cart_item_key );
?>
but didn't work
my latest try:
$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";
}
}
and I got this result int(48)int(47)
can anyone help me please.
Show very specific item attribute 'colour1' in WooCommerce cart
For some reasons get_attributes() crashing, you can try
how to fetch attribute and value in cart page?
please add below function in function.php file