D
D
devele2016-04-24 21:08:36
WordPress
devele, 2016-04-24 21:08:36

Display woocommerce products?

Good afternoon, the question is how to display the attributes of each product in the product category, not all, some.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Kozlov, 2016-04-25
@devele

To display a product card in a category, the wp-content/plugins/woocommerce/templates/content-product.php
template is used. Also, the category templates (for certain card blocks) are located in the wp-content/plugins/woocommerce/templates/loop folder
. place template add:

<?php
global $product;
$attributes = $product->get_attributes();
foreach ( $attributes as $attribute ){
     $name = wc_attribute_label( $attribute['name'] );
     if ($name != 'не нужный атрибут') {//тут пишем условия что бы не выводить ненужный атрибут
        echo $name;
        if ( $attribute['is_taxonomy'] ) {
  $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
  echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
        } else {
          $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
          echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
        }
     }
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question