'; if ( 'default' === $layout ) { echo wp_kses_post( $this->render_woocommerce_page_title( $layout ) ); } $this->render_woocommerce_header_background(); echo ''; return ''; } /** * Display titile in content for WooCommerce pages. */ public function woocommerce_title_in_content() { $layout = apply_filters( 'hestia_header_layout', get_theme_mod( 'hestia_header_layout', 'default' ) ); if ( 'default' === $layout ) { return; } if ( is_product_category() ) { return; } echo $this->render_woocommerce_page_title( $layout ); } /** * Display image in content. * * @return void */ public function woocommerce_image_in_content() { if ( is_product() || is_cart() || is_checkout() || is_product_category() ) { return; } $layout = apply_filters( 'hestia_header_layout', get_theme_mod( 'hestia_header_layout', 'default' ) ); if ( 'classic-blog' !== $layout ) { return; } $image_url = $this->get_woocommerce_header_image_url(); if ( empty( $image_url ) ) { return; } $image_id = attachment_url_to_postid( $image_url ); $image1_alt = ''; if ( $image_id ) { $image1_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true ); } $image_markup = '' . esc_attr( $image1_alt ) . ''; if ( is_shop() ) { $image_markup = '
' . $image_markup . '
'; } echo $image_markup; } /** * Render WooCommerce header content. * * @param string $layout Layout of the header. * * @return string */ private function render_woocommerce_page_title( $layout ) { $title_class = 'hestia-title'; $wrapper_class = 'col-md-10 col-md-offset-1 text-center'; if ( 'default' !== $layout ) { $title_class .= ' title-in-content'; $wrapper_class = 'col-md-12'; } $header_content_output = '
'; $header_content_output .= '
'; $header_content_output .= '
'; $header_content_output .= '

'; if ( is_shop() ) { $header_content_output .= woocommerce_page_title( false ); } if ( is_product() || is_cart() || is_checkout() ) { $header_content_output .= the_title( '', '', false ); } if ( is_product_category() ) { $header_content_output .= get_the_archive_title(); } $header_content_output .= '

'; if ( is_product_category() ) { $header_content_output .= '
' . get_the_archive_description() . '
'; } $header_content_output .= '
'; $header_content_output .= '
'; $header_content_output .= '
'; return $header_content_output; } /** * Render header on WooCommerce pages. * * @return void */ private function render_woocommerce_header_background() { $background_image = apply_filters( 'hestia_header_image_filter', $this->get_woocommerce_header_image_url() ); $customizer_background_image = get_background_image(); $header_filter_div = '
get_single_product_background(); if ( ! empty( $thumbnail ) ) { return esc_url( $thumbnail ); } } $shop_id = get_option( 'woocommerce_shop_page_id' ); if ( is_product_category() ) { $thumbnail = $this->get_product_category_background( $shop_id ); if ( ! empty( $thumbnail ) ) { return esc_url( $thumbnail ); } } if ( is_shop() ) { $thumbnail = $this->get_shop_page_background( $shop_id ); if ( ! empty( $thumbnail ) ) { return esc_url( $thumbnail ); } } return esc_url( $thumbnail ); } /** * This is the single product header image. * This function searches in all categories of a product for a thumbnail. * If the category have a thumbnail, get the image and search further * to find the last category that have a thumbnail. * * @return bool|string */ private function get_single_product_background() { // Bail if it's not WooCommerce or if not single product. if ( ! hestia_check_woocommerce() || ! is_product() ) { return false; } $terms = get_the_terms( get_queried_object_id(), 'product_cat' ); if ( empty( $terms ) ) { return false; } $thumb_tmp = ''; foreach ( $terms as $term ) { $categ_thumb = $this->get_category_thumbnail( $term->term_id ); if ( ! empty( $categ_thumb ) ) { $thumb_tmp = $categ_thumb; } } return $thumb_tmp; } /** * This is the product category header image. * * @param string $shop_id Shop page id. * @return string */ private function get_product_category_background( $shop_id ) { $category = get_queried_object(); /** * Try to get category thumbnail. */ $category_thumbnail = $this->get_category_thumbnail( $category->term_id ); if ( ! empty( $category_thumbnail ) ) { return $category_thumbnail; } /** * If category does not have a thumbnail, try to get page thumbnail */ if ( empty( $shop_id ) ) { return ''; } $thumb_tmp = get_the_post_thumbnail_url( $shop_id ); if ( ! empty( $thumb_tmp ) ) { return $thumb_tmp; } return ''; } /** * Get background for shop page. * * @param string $shop_id Shop page id. * * @return bool */ private function get_shop_page_background( $shop_id ) { // Bail if it's not WooCommerce or if not single product. if ( empty( $shop_id ) ) { return false; } return get_the_post_thumbnail_url( $shop_id ); } /** * Get Woo category thumbnail. * * @param int $term_id Term ID. * @return string|bool */ private function get_category_thumbnail( $term_id ) { if ( ! empty( $term_id ) ) { $category_thumbnail = get_term_meta( $term_id, 'thumbnail_id', true ); } // Get product category's image. return ! empty( $category_thumbnail ) ? wp_get_attachment_url( $category_thumbnail ) : false; } }