W
W
WebforSelf2020-08-04 12:59:26
WordPress
WebforSelf, 2020-08-04 12:59:26

Outputting multiple woocommerce attributes?

There is such a function that displays one attribute, how to make it possible to display 3 selected attributes?

function productShoes() {
  global $product;
  // Получаем элементы таксономии атрибута shoes
  $attribute_names = get_the_terms($product->get_id(), 'pa_shoes');
  $attribute_name = "pa_shoes";
  if ($attribute_names) {
    // Вывод имени атрибута shoes
    echo wc_attribute_label($attribute_name);
    // Выборка значения заданного атрибута
    foreach ($attribute_names as $attribute_name):
      // Вывод значений атрибута shoes
      echo $attribute_name->name;
    endforeach;
  }
}
// Определяем место вывода атрибута
add_action('woocommerce_single_product_summary', 'productShoes', 61);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WebforSelf, 2020-08-05
@WebforSelf

/**
 * Вывод атрибутов на странице товара
 */

function productFeature() {
  global $post;
  $attribute_names = array( 'pa_razmer-domika', 'pa_materialy' );

  foreach ( $attribute_names as $attribute_name ) {
    $taxonomy = get_taxonomy( $attribute_name );

    if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
      $terms = wp_get_post_terms( $post->ID, $attribute_name );
      $terms_array = array();
      if ( ! empty( $terms ) ) {
        foreach ( $terms as $term ) {
          $archive_link = get_term_link( $term->slug, $attribute_name );
          $full_line = '<a href="' . $archive_link . '">'. $term->name . '</a>';
          array_push( $terms_array, $full_line );
        }
        echo '<span class="attribute">' . $taxonomy->labels->name . ' ' . implode( $terms_array, ', ' ). '</span>';
      }
    }
  }
}

// Определяем место вывода атрибута
add_action('woocommerce_single_product_summary', 'productFeature', 7);

P
Pychev Anatoly, 2020-08-04
@pton

We call this function 3 times, respectively, change the value of pa_shoes topa_****

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question