mercredi 20 mars 2019

Conditional logic for php-snippet to hide banner + title on product category archive pages in Woocommerce

I am working with a WordPress theme which includes woocommerce, and I'm aiming to modify the appearance of the standard shop-categories-pages. Unfortunately I’m a WP-newbie and not very familiar with coding. Therefore I would be very grateful for your help.

I'm failing for days to create a php-snippet for my child-theme functions.php, that hides the banner and the title ONLY on the Shop-categories- and subcategories-pages, WITHOUT hiding them on the Shop-Starting-page.

Although I found a working code to effectively hide the banner and title on EACH Woocommerce page,

add_filter( 'woocommerce_show_page_title', '__return_false' );

and had some success with this conditional-logic-code-example from businessbloomer.com

add_action( 'woocommerce_before_main_content', 'bbloomer_loop_cat' );

function bbloomer_loop_cat() {

if ( is_product_category( 'segel' ) ) {
echo 'This will show on the Segel Cat page';
} else {
echo 'This will show on all other Woo pages';
}

}

I’m constantly failing to combine these 2 codes. I guess I have tried dozens of combinations but nothing seems to work. Therefore I desperately need some support and would appreciate any help.

With kind regards Reca

P.S: Some additional information: Here is some code of the archive-product,php, if this is relevant

    <div class="woocommerce-products-header page-banner">

        <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

            <div class="title-inside shop-page" style="background-image: url(<?php echo esc_url( $banner_url ); ?>);">

                <div class="banner-wrapper <?php if ( empty( $banner_url ) ) echo 'no-banner-img' ?>">
                    <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>

The CSS-command .title-inside.shop-page { display: none; } works also perfect in hiding banner and title on ALL Woocommerce pages. Unfortunately I‘m failing here in total to add some if-conditions. Please see my separate question, depending CSS.

Aucun commentaire:

Enregistrer un commentaire