I’m writing a spare parts website using the shoptimizer theme. Some category pages have complicated drawings that need to be displayed large as usual, which shoptimizer does as the category page displays the photo in large underneath the title. Other categories I could really do with the category pages displaying no category image at all, to bring the content up.
I can’t seem to get my head around changing the archive-product.php template, so that it displays the category image for some pages and not for others. Is it possible someone can help me with this?
The part of the archive-product.php that pulls this image and the category description I think is the following:
<?php
/**
* Hook: woocommerce_archive_description.
*
* @hooked woocommerce_taxonomy_archive_description - 10
* @hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
</header>
So I’d like a second template that I could to apply to certain templates, that doesn’t Have this woocommerce_archive_description action, and some how apply that to specific categories, perhaps with the category ID code.
2
Answers
Thanks to Richard in the comments, I've now discovered the answer to this, by modifying a code snippet in the Shoptimizer docs:
I can confirm this is working on my website, successfully removing the category banner image from the categories which ID's are in the array.
You dont need to alter template for that. Look into
content-product-cat.php
template and you will notice actionwoocommerce_before_subcategory_title
which will call forwoocommerce_subcategory_thumbnail
function . If we look into that function, you will notice if you dont provide image will load the default onewc_placeholder_img_src()
.So you need to use
remove_action('woocommerce_before_subcategory_title','woocommerce_subcategory_thumbnail');
to remove the original function and provide your own function.I’m going to simply copy/paste the original function and remove the else part. You can alter the function as you want.