Итак, на мой взгляд, мне нужно сделать следующие шаги:
0) получить все идентификаторы продуктов из категории с идентификатором
- получить все атрибуты продуктов с этими идентификаторами
- если атрибутом продукта является $somename, получить его опцию и сохранить его в массиве $options
И что сделано:
Код: Выделить всё
function get_options_of_attribute() {
$catid = "6776"; // T-shirts
$attr = "size";
$all_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $current_cat_id,
'operator' => 'IN'
)
),
));
$ids = '';
$values = '';
foreach ( $all_ids as $id ) {
$ids .= $id.' ';
foreach( wc_get_product_terms( $id, $attr ) as $attribute_value ){
$values .= $attribute_value.' ';
}
}
Код: Выделить всё
return $values;
}
add_shortcode( 'listofoptions', 'get_options_of_attribute' );
Подробнее здесь: https://stackoverflow.com/questions/673 ... the-catego