Php 在购物车中显示特定项目属性

Php 在购物车中显示特定项目属性,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我有一些代码(我在这里修改并使用了这些代码)显示了包含属性的完整列表,但我只想使用特定属性,比如“color1”来生成SVG文件 <?php $item_data = $cart_item['data']; $attributes = $item_data->get_attributes(); foreach ( $attributes as $attribute ) { $out ='';

我有一些代码(我在这里修改并使用了这些代码)显示了包含属性的完整列表,但我只想使用特定属性,比如“color1”来生成SVG文件

    <?php
    
$item_data = $cart_item['data'];
$attributes = $item_data->get_attributes();

    foreach ( $attributes as $attribute ) 
    {      
            $out ='';
            $out .= $attribute['name'] . ': ';
            $out .= $attribute['value'] . '<br />';
            echo $out;
    }
    ?>

刚刚找到的解决方案:

<?php

$item_data = $cart_item['data'];
$attributes = $item_data->get_attributes();

    foreach ( $attributes as $attribute ) 
    {      
        if ( $attribute['name'] == 'colour1' ) {
            $out ='';
            $out .= $attribute['name'] . ': ';
            $out .= $attribute['value'] . '<br />';
            echo $out;
    }
    }
    ?>

刚刚找到的解决方案:

<?php

$item_data = $cart_item['data'];
$attributes = $item_data->get_attributes();

    foreach ( $attributes as $attribute ) 
    {      
        if ( $attribute['name'] == 'colour1' ) {
            $out ='';
            $out .= $attribute['name'] . ': ';
            $out .= $attribute['value'] . '<br />';
            echo $out;
    }
    }
    ?>