W
W
WebforSelf2020-08-05 12:17:37
WordPress
WebforSelf, 2020-08-05 12:17:37

Remove word "Product" from woocommerce attribute name?

There is such a function

function productFeature() {
  global $post;
  $attribute_names = array( 'pa_razmer-domika', 'pa_materialy' , 'pa_ves-v-sobrannom-vide' );
    echo '<span class="attribute">';
  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 ) {
          $full_line = '<span>'. $term->name . '</span>';
          array_push( $terms_array, $full_line );
        }
        echo '<span class="attribute_item">' . $taxonomy->labels->name . ' ' . implode( $terms_array, ', ' ). '</span>';
      }
    }
  }
     echo '</span>';	
}

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


Displays an array of attributes as needed, but for some reason adds "Product" to the attribute name, how to remove it?

Item House size 88x33x117cm
Item Materials Wood, Plastic
Item Assembled weight 18 kg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2020-08-05
@WebforSelf

Well, I would just replace the product with an empty space...
If I didn't make a mistake with the variable, then something like this:

function productFeature() {
  global $post;
  $attribute_names = array( 'pa_razmer-domika', 'pa_materialy' , 'pa_ves-v-sobrannom-vide' );
    echo '<span class="attribute">';
  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 ) {
          $full_line = '<span>'. $term->name . '</span>';
          array_push( $terms_array, $full_line );
        }
       $tovar_name = str_replace('Товар ',  '', $taxonomy->labels->name);
        echo '<span class="attribute_item">' .  $tovar_name . ' ' . implode( $terms_array, ', ' ). '</span>';
      }
    }
  }
     echo '</span>';	
}

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question