【问题标题】:Show specific item attribute in WooCommerce cart在 WooCommerce 购物车中显示特定商品属性
【发布时间】:2020-07-13 20:16:39
【问题描述】:

我的代码(我修改并从这里Woocommerce get specific attribute value on cart page 获取)显示了包含属性的完整列表,但我只想使用特定属性,比如说“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 wordpress woocommerce


    【解决方案1】:

    刚刚找到解决方案:

    <?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;
        }
        }
        ?>
    

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 2018-09-05
      • 2021-05-05
      • 2017-02-22
      • 2020-11-15
      • 2018-07-31
      相关资源
      最近更新 更多