Banner personalizzato su archivio prodotti
Lo snippet di seguito permette di aggiungere un banner con gli elementi shortcode di Enfold (avia schortcode) nelle pagine loop degli archivi prodotti di Woocommerce. In questa maniera il banner può essere cambiato a seconda della categoria del prodotto scelta.
Lo snippet va inserito nel file del tema child functions.php
E’ necessario conoscere l’ID della categoria e inserirlo nella funzione php per avere le condizioni di quando far apparire il banner.
//======================= /* Conditional Tag to check if its a term or any of its children * * @param $terms - (string/array) list of term ids * * @param $taxonomy - (string) the taxonomy name of which the holds the terms. */ function is_or_descendant_tax( $terms,$taxonomy){ if (is_tax($taxonomy, $terms)){ return true; } foreach ( (array) $terms as $term ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $term, $taxonomy); if ( $descendants && is_tax($taxonomy, $descendants) ) return true; } return false; } //========================== //The function is named woo_banner_category_page add_action('woocommerce_before_main_content', 'woo_banner_category_page', 5); // Here the construct of the function function woo_banner_category_page() { if(!is_tax('product_cat')) return; if(is_or_descendant_tax(16, product_cat)) //condition for cat-id (in this example cat-id = 16) {?> <!-- creates an avia section 430px height with a background image--> <div id="av_section_1" class="avia-section main_color avia-section-default avia-no-shadow av-section-color-overlay-active avia-bg-style-scroll avia-builder-el-0 avia-builder-el-no-sibling av-minimum-height av-minimum-height-custom container_wrap fullsize" style="background-repeat: no-repeat; background-image: url(https://url-for-the-bcg-image.jpg); background-attachment: scroll; background-position: center center; " data-section-bg-repeat="no-repeat"> <div class="av-section-color-overlay-wrap"> <div class="av-section-color-overlay" style="opacity: 0.5; background-color: #ffffff; "></div> <div class="container" style="height:430px"> <main class="template-page content av-content-full alpha units" role="main" itemprop="mainContentOfPage"> <div class="post-entry post-entry-type-page post-entry-493"> <div class="entry-content-wrapper clearfix"> <?php //prints the avia shortcode (in our case the shop logo followed by the name of the category) echo do_shortcode(" <div class="avia-image-container avia_animated_image avia_animate_when_almost_visible bottom-to-top av-styling- avia-builder-el-5 el_before_av_heading avia-builder-el-first logo-centro-banner avia-align-center " itemprop="image" itemscope="itemscope" itemtype="https://schema.org/ImageObject"><div class="avia-image-container-inner"><div class="avia-image-overlay-wrap"><img class="avia_image " src="https://url-for-the-logo-image.jpg" alt="" title="" itemprop="thumbnailUrl"></div></div></div> <div style="padding-bottom:14px; " class="av-special-heading av-special-heading-h1 blockquote modern-quote modern-centered avia-builder-el-6 el_after_av_image el_before_av_image "><h1 class="av-special-heading-tag " itemprop="headline">E-Shop</h1><div class="av-subheading av-subheading_below " style="font-size:28px;"><p> NAME OF CATEGORY</p> </div><div class="special-heading-border"><div class="special-heading-inner-border"></div></div></div> "); ?> </div> </div> </main> </div> </div> </div> <?php } elseif (is_or_descendant_tax(14, product_cat)) //condition fo cat-id (in this example cat-id = 14) {?> <!-- creates an avia section 430px height with a background image--> <div id="av_section_1" class="avia-section main_color avia-section-default avia-no-shadow av-section-color-overlay-active avia-bg-style-scroll avia-builder-el-0 avia-builder-el-no-sibling av-minimum-height av-minimum-height-custom container_wrap fullsize" style="background-repeat: no-repeat; background-image: url(https://url-for-the-bcg-image.jpg); background-attachment: scroll; background-position: center center; " data-section-bg-repeat="no-repeat"> <div class="av-section-color-overlay-wrap"> <div class="av-section-color-overlay" style="opacity: 0.5; background-color: #ffffff; "></div> <div class="container" style="height:430px"> <main class="template-page content av-content-full alpha units" role="main" itemprop="mainContentOfPage"> <div class="post-entry post-entry-type-page post-entry-493"> <div class="entry-content-wrapper clearfix"> <?php //prints the avia shortcode (in our case the shop logo followed by the name of the category) echo do_shortcode(" <div class="avia-image-container avia_animated_image avia_animate_when_almost_visible bottom-to-top av-styling- avia-builder-el-7 el_after_av_heading el_before_av_heading logo-centro-banner avia-align-center " itemprop="image" itemscope="itemscope" itemtype="https://schema.org/ImageObject"><div class="avia-image-container-inner"><div class="avia-image-overlay-wrap"><img class="avia_image " src="https://url-for-the-logo-image.jpg" alt="" title="" itemprop="thumbnailUrl"></div></div></div> <div style="padding-bottom:14px; " class="av-special-heading av-special-heading-h1 blockquote modern-quote modern-centered avia-builder-el-8 el_after_av_image avia-builder-el-last "><h1 class="av-special-heading-tag " itemprop="headline">E-Shop</h1><div class="av-subheading av-subheading_below " style="font-size:28px;"><p> NAME OF CATEGORY</p> </div><div class="special-heading-border"><div class="special-heading-inner-border"></div></div></div> "); ?> </div> </div> </main> </div> </div> </div> <?php } }