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.
Thanks to Richard in the comments, I've now discovered the answer to this, by modifying a code snippet in the Shoptimizer docs:
add_action( 'wp', function() {
// Define the category IDs where you want to remove the description and image
$category_ids = array( 50, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 );
// Check if the current page is a category page and matches the specified category IDs
if ( is_product_category( $category_ids ) ) {
remove_action( 'woocommerce_archive_description', 'shoptimizer_woocommerce_taxonomy_archive_description' );
remove_action( 'woocommerce_archive_description', 'shoptimizer_category_image', 20 );
}
}, 20 );
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.