R
R
Roman Filippov2018-12-28 12:30:28
WordPress
Roman Filippov, 2018-12-28 12:30:28

How to create a condition for issuing goods from several categories?

There is a filter on the site in which you can choose to filter products by several categories, while we get this kind of link:
/cat/mens-home-suits,underclothers,chemise-and-tunics/
There is also a code responsible for displaying an additional header in categories :

// Изображение категории на странице рубрики
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 0 );
function woocommerce_category_image() {
    if ( is_product_category() ){
      global $wp_query;
      $cat = $wp_query->get_queried_object();
      $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
      $image = wp_get_attachment_url( $thumbnail_id );
      if ( $image ) {
        echo '<div class="archive-header" style="background: url(' . $image . ') no-repeat 50%; background-size: cover;">';
            echo '<div class="archive-title"><h1 class="page-title">';
            woocommerce_page_title();
            echo '</h1></div>';
    }
        else {
            echo '<div class="archive-header">';
            echo '<h1 class="woocommerce-products-header__title page-title">';
            woocommerce_page_title();
            echo '</h1></div>';
        }
  }
}

But the problem is that if the filtering goes through several categories, then the image and title are taken from the first category that participates in the filtering.
What condition should be written so that when filtering from two categories, fixed values ​​​​of the title and image for the add. hats?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question