WordPress プラグイン woocommerce で商品一覧に出力される属性に固有の Class を付与したい
いつもお世話になっております。
WordPress プラグイン woocommerce で商品一覧に出力される属性に、固有の Class を付与したいと思っているのですが、現在の PHP Code では実現できません。
出力される HTML は下記の形です。
html
1<div class="icon-wrap2"> 2 <p>属性</p> 3 <p>属性</p> 4 <p>属性</p> 5 <p>属性</p> 6</div>
こちらの p タグに固有の Class を付けたいと思っております。詳しい方がいらっしゃいましたら、ご教授のほど宜しくお願い致します。
発生している問題・エラーメッセージ
エラーはございません。
該当のソースコード
php
1$attributes = $product->get_attributes(); 2// Start the loop 3foreach ( $attributes as $attribute ) : ?> 4 5<div class="icon-wrap2"> 6<?php 7// Check and output, adopted from /templates/single-product/product-attributes.php 8 if ( $attribute['is_taxonomy'] ) { 9 $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) ); 10 echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( '</p><p>', $values ) ) ), $attribute, $values ); 11 } 12 else { 13 // Convert pipes to commas and display values 14 $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) ); 15 echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( '</p><p>', $values ) ) ), $attribute, $values ); 16 } 17?> 18</div> 19<?php endforeach;
試したこと
php
1// For WooCommerce below version 3.0 2add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 ); 3function custom_attributes_display(){ 4 5 // Just for product category archives pages 6 if(is_product_category()){ 7 global $product; 8 9 // the array of attributes names 10 $attribute_names = array('pa_test', 'pa_rank'); 11 foreach( $attribute_names as $key => $attribute_name ) { 12 13 // Getting the value of an attribute 14 $attribute_value = array_shift(wc_get_product_terms( $product->id, $attribute_name)); 15 16 // Displays only if attribute exist for the product 17 if(!empty($attribute_value) || $attribute_value == '0' ){ // Updated 18 echo $attribute_value; 19 20 // Separating each number by a " / " 21 if($key < 3) echo ' / '; 22 } 23 } 24 } 25}
$attribute_names = array('pa_test', 'pa_rank');
で属性を指定してみましたが、正しく動きませんでした。
補足情報(FW/ツールのバージョンなど)
Adobe Dreamweaver cc
あなたの回答
tips
プレビュー