Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Logo for Different WooCommerce Categories WordPress

  • SOLVED

Basically, I'm trying to figure how to use conditional tags to change the logo for certain categories on my site.

I have a main logo but for category "shirt" for example, I would want another logo shown for instance.

I know the answer is probably easy but can't seem to Google what I'm looking for, which is why I'm posting here.

Here's the code in my template where logo appears:



<?php


// show logo


$logo = porto_logo();


echo $logo;


?>



That's pretty much all I got for right now.

Thanks for any assistance you can give me.

Answers (3)

2018-04-13

Reigel Gallarde answers:

for category page, this should work

<?php

$logo = porto_logo();
if ( is_product_category() ) {

if ( is_product_category( 'test' ) ) {
echo 'HTML';
} elseif ( is_product_category( '2' ) ) {
echo 'HTML';
} else {
echo $logo;
}

}

?>


but you need something else on the product page... is_product_category() will return false there...

You can add is_product() to check if it's product page... then use has_term to check for product categories.
https://codex.wordpress.org/Function_Reference/has_term



<?php

$logo = porto_logo();
if ( is_product_category() || is_product() ) {

if ( is_product_category( 'test' ) || has_term( 'test', 'product_cat' )) {
echo 'test';
} elseif ( is_product_category( '2' ) || has_term( '2', 'product_cat' ) ) {
echo '2';
} else {
echo $logo;
}

}

?>


Brennen Jones comments:

I think your answer did the trick...

When I added the has_term to my code, it does the trick. The logo carries over. :-)

I appreciate ya.

2018-04-12

Francisco Javier Carazo Gil answers:

Good afternoon,

Firstly, we need to see the code of porto_logo() in order to see if there is some hook available there.

I am going to look for this code into some porto theme.


Francisco Javier Carazo Gil comments:

You have the function defined in inc/functions/layout.php of Porto.

There you will see this line:

return apply_filters('porto_logo', ob_get_clean());


So you can use this filter to change it with your own conditional.


Brennen Jones comments:

I don't see that line in the file but I don't need to change the hook or even use the hook for this.

If I have to, I can use HTML to make something like this:



<?php

$logo = porto_logo();
if ( is_product_category() ) {

if ( is_product_category( 'test' ) ) {
echo 'HTML';
} elseif ( is_product_category( '2' ) ) {
echo 'HTML';
} else {
echo $logo;
}

}

?>




Or something like this. This is some code I grabbed offline that I modified and it works.

My problem is that on the product pages, it isn't working within the category page.

The category archive page swaps the logo out just fine but if I go into an item from within that category logo doesn't get swapped out.


Francisco Javier Carazo Gil comments:

It could be something like it.

add_filter('porto_logo', 'my_porto_logo', 10, 1 );
function my_porto_logo( $default ){

if ( is_product_category() ) {

if ( is_product_category( 'test' ) ) {
echo 'HTML';
} elseif ( is_product_category( '2' ) ) {
echo 'HTML';
else{
return $default;
}
}


Brennen Jones comments:

Check this link out to see what I mean:

https://bit.ly/2HbScsP

You'll see a dummy logo in place on that page but when you click on a product on that page, the dummy logo doesn't display on the product page.

That's my issue right now.

Is showing the logo on the category page and the products within the category.

2018-04-12

Arnav Joy answers:

Are you using child theme ??
If you want I can code this for you..
Please let me know and contact me at - [email protected]