Title: Вывод атрибутов в описании товара
Last modified: 03.12.2020

---

# Вывод атрибутов в описании товара

 *  [simatic007](https://ru.wordpress.org/support/users/simatic007/)
 * (@simatic007)
 * [5 лет, 11 месяцев назад](https://ru.wordpress.org/support/topic/%d0%b2%d1%8b%d0%b2%d0%be%d0%b4-%d0%b0%d1%82%d1%80%d0%b8%d0%b1%d1%83%d1%82%d0%be%d0%b2-%d0%b2-%d0%be%d0%bf%d0%b8%d1%81%d0%b0%d0%bd%d0%b8%d0%b8-%d1%82%d0%be%d0%b2%d0%b0%d1%80%d0%b0/)
 * Добрый день.
    Мне необходимо выводить атрибуты товара в short description [https://prnt.sc/vuu4l8](https://prnt.sc/vuu4l8)
   Сейчас приходится руками копировать текст из атрибутов товара, а хотелось бы 
   выводить атрибут в виде шорткода, ну или еще как то. То есть, чтобы атрубуты 
   товара автоматически вставлялись в нужном месте описания. Но насколько понял 
   стандартного woocommerce шорткода для вывода атрибута в произвольном месте нет.
   Как решить данный вопрос? Готового плагина под эту задачу не нашел.

Просмотр 1 ответа (всего 1)

 *  Автор [simatic007](https://ru.wordpress.org/support/users/simatic007/)
 * (@simatic007)
 * [5 лет, 11 месяцев назад](https://ru.wordpress.org/support/topic/%d0%b2%d1%8b%d0%b2%d0%be%d0%b4-%d0%b0%d1%82%d1%80%d0%b8%d0%b1%d1%83%d1%82%d0%be%d0%b2-%d0%b2-%d0%be%d0%bf%d0%b8%d1%81%d0%b0%d0%bd%d0%b8%d0%b8-%d1%82%d0%be%d0%b2%d0%b0%d1%80%d0%b0/#post-12201492)
 * Нашел следующий топик по теме [https://stackoverflow.com/questions/39394127/woocommerce-display-single-product-attributes-with-shortcodes-in-frontend](https://stackoverflow.com/questions/39394127/woocommerce-display-single-product-attributes-with-shortcodes-in-frontend)
 * Код
 *     ```
       /**
        * Attributes shortcode callback.
        */
       function so_39394127_attributes_shortcode( $atts ) {
   
           global $product;
   
           if( ! is_object( $product ) || ! $product->has_attributes() ){
               return;
           }
   
           // parse the shortcode attributes
           $args = shortcode_atts( array(
               'attributes' => array_keys( $product->get_attributes() ), // by default show all attributes
           ), $atts );
   
           // is pass an attributes param, turn into array
           if( is_string( $args['attributes'] ) ){
               $args['attributes'] = array_map( 'trim', explode( '|' , $args['attributes'] ) );
           }
   
           // start with a null string because shortcodes need to return not echo a value
           $html = '';
   
           if( ! empty( $args['attributes'] ) ){
   
               foreach ( $args['attributes'] as $attribute ) {
   
                   // get the WC-standard attribute taxonomy name
                   $taxonomy = strpos( $attribute, 'pa_' ) === false ? wc_attribute_taxonomy_name( $attribute ) : $attribute;
   
                   if( taxonomy_is_product_attribute( $taxonomy ) ){
   
                       // Get the attribute label.
                       $attribute_label = wc_attribute_label( $taxonomy );
   
                       // Build the html string with the label followed by a clickable list of terms.
                       // Updated for WC3.0 to use getters instead of directly accessing property.
                       $html .= get_the_term_list( $product->get_id(), $taxonomy, '<li class="bullet-arrow">' . $attribute_label . ': ' , ', ', '</li>' ); 
                   }
   
               }
   
               // if we have anything to display, wrap it in a <ul> for proper markup
               // OR: delete these lines if you only wish to return the <li> elements
               if( $html ){
                   $html = '<ul class="product-attributes">' . $html . '</ul>';
               }
   
           }
   
           return $html;
       }
       add_shortcode( 'display_attributes', 'so_39394127_attributes_shortcode' );
       ```
   
 * Скопировал в отдельный плагин, установил и запустил его. Но выводит только список
   аргументов. При попытке вывести отдельный атрибут просто остается шорткод [display_attributes
   attributes=»color|material»]
    -  Ответ изменён 5 лет, 11 месяцев назад пользователем [simatic007](https://ru.wordpress.org/support/users/simatic007/).

Просмотр 1 ответа (всего 1)

 Тема «Вывод атрибутов в описании товара» закрыта для новых ответов.

 * Форум: [WooCommerce](https://ru.wordpress.org/support/forum/woocommerce/)
 * 1 ответ
 * 1 участник
 * Последний ответ: [simatic007](https://ru.wordpress.org/support/users/simatic007/)
 * Последняя активность: [5 лет, 11 месяцев назад](https://ru.wordpress.org/support/topic/%d0%b2%d1%8b%d0%b2%d0%be%d0%b4-%d0%b0%d1%82%d1%80%d0%b8%d0%b1%d1%83%d1%82%d0%be%d0%b2-%d0%b2-%d0%be%d0%bf%d0%b8%d1%81%d0%b0%d0%bd%d0%b8%d0%b8-%d1%82%d0%be%d0%b2%d0%b0%d1%80%d0%b0/#post-12201492)
 * Статус: нерешённая

## Темы

### Самые популярные темы

### Темы без ответов

### Без вопроса

### Решённые

### Нерешённые

### Все темы
