-
Использование функции
get_the_terms:$product = wc_get_product( $product_id ); $attribute_names = array(); foreach ( $product->get_attributes() as $attribute ) { $attribute_names[] = str_replace( 'pa_', '', $attribute->get_name() ); } -
Использование функции
get_post_meta:$product_id = get_the_ID(); $attribute_names = array(); $attributes = get_post_meta( $product_id, '_product_attributes', true ); foreach ( $attributes as $attribute ) { $attribute_names[] = str_replace( 'pa_', '', $attribute['name'] ); } -
Использование функции WooCommerce
wc_attribute_label:$product_id = get_the_ID(); $attribute_names = array(); $attributes = get_post_meta( $product_id, '_product_attributes', true ); foreach ( $attributes as $attribute ) { $attribute_names[] = wc_attribute_label( $attribute['name'] ); }
Обратите внимание, что предоставленные фрагменты кода предполагают, что у вас установлен WooCommerce и доступны необходимые функции.