Hide sub category titles on single parent sub category archive page WooCommerce





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm building a WP ecommerce site with multiple categories & sub-categories and need to remove the sub-category titles on just one archive page (slug = 'paving-brands'):



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-brands/



All other category & sub category pages still require the sub category titles, this page for example should remain as it is now:



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-stone-types/



Many thanks.










share|improve this question























  • Are you okay with using css? Try this .archive.term-paving-brands category-name { display: none; }. This should hide all category titles on paving brands page.

    – Bariel R.
    Oct 3 '16 at 12:30




















1















I'm building a WP ecommerce site with multiple categories & sub-categories and need to remove the sub-category titles on just one archive page (slug = 'paving-brands'):



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-brands/



All other category & sub category pages still require the sub category titles, this page for example should remain as it is now:



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-stone-types/



Many thanks.










share|improve this question























  • Are you okay with using css? Try this .archive.term-paving-brands category-name { display: none; }. This should hide all category titles on paving brands page.

    – Bariel R.
    Oct 3 '16 at 12:30
















1












1








1








I'm building a WP ecommerce site with multiple categories & sub-categories and need to remove the sub-category titles on just one archive page (slug = 'paving-brands'):



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-brands/



All other category & sub category pages still require the sub category titles, this page for example should remain as it is now:



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-stone-types/



Many thanks.










share|improve this question














I'm building a WP ecommerce site with multiple categories & sub-categories and need to remove the sub-category titles on just one archive page (slug = 'paving-brands'):



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-brands/



All other category & sub category pages still require the sub category titles, this page for example should remain as it is now:



http://redyearclients.co.uk/PandF/product-category/exterior-paving/paving-stone-types/



Many thanks.







php wordpress woocommerce hook-woocommerce






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 3 '16 at 12:22









Red YearRed Year

255




255













  • Are you okay with using css? Try this .archive.term-paving-brands category-name { display: none; }. This should hide all category titles on paving brands page.

    – Bariel R.
    Oct 3 '16 at 12:30





















  • Are you okay with using css? Try this .archive.term-paving-brands category-name { display: none; }. This should hide all category titles on paving brands page.

    – Bariel R.
    Oct 3 '16 at 12:30



















Are you okay with using css? Try this .archive.term-paving-brands category-name { display: none; }. This should hide all category titles on paving brands page.

– Bariel R.
Oct 3 '16 at 12:30







Are you okay with using css? Try this .archive.term-paving-brands category-name { display: none; }. This should hide all category titles on paving brands page.

– Bariel R.
Oct 3 '16 at 12:30














1 Answer
1






active

oldest

votes


















1














Update - Nov 2018




The easiest way for that purpose is to make a custom conditional function that you will use in the concerned related template content-product_cat.php where the this subcategory title is hooked.




1) The conditional function



Here is that code:



function is_parent_category( $subcategory_term, $parent_category_term_slug ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return $parent_term->slug == $parent_category_term_slug ? true : false;
}


This code goes in function.php file of your active child theme (or theme) or also in any plugin file.





2) Overriding via your theme **content-product_cat.php WooCommerce template.**




If not done yet, inside your active child theme (or theme) create a woocommerce folder. Then copy from woocommerce plugin templates folder a file named content-product_cat.php inside the fresh created woocommerce folder in your active child theme (or theme).




The open/edit this copied content-product_cat.php template file.



Replace the following line:



do_action( 'woocommerce_shop_loop_subcategory_title', $category );


By this:



if( ! is_parent_category( $category, 'exterior-paving' ) ) {
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
}


Save, you are done. Now as you wished, all the brand titles only on the 'paving-brands' archive page will be removed.



This code is tested and fully functional.





ADDITION: Handling Multiple parent category slugs:



To handle multiple parent category slugs use the following instead (from an array of slugs):



function is_parent_category( $subcategory_term, $parent_category_term_slugs ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return in_array($parent_term->slug, $parent_category_term_slug ) ? true : false;
}


USAGE example:



// Reminder: $category is a WP_Term object
if ( is_parent_category( $category, array( 'clothing', 'posters' ) ) {
// Do something (matching subcategory)
} else {
// Do something else (no matching subcategory)
}





share|improve this answer


























  • Thank you so much, really appreciate the help.

    – Red Year
    Oct 3 '16 at 14:35












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39831556%2fhide-sub-category-titles-on-single-parent-sub-category-archive-page-woocommerce%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Update - Nov 2018




The easiest way for that purpose is to make a custom conditional function that you will use in the concerned related template content-product_cat.php where the this subcategory title is hooked.




1) The conditional function



Here is that code:



function is_parent_category( $subcategory_term, $parent_category_term_slug ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return $parent_term->slug == $parent_category_term_slug ? true : false;
}


This code goes in function.php file of your active child theme (or theme) or also in any plugin file.





2) Overriding via your theme **content-product_cat.php WooCommerce template.**




If not done yet, inside your active child theme (or theme) create a woocommerce folder. Then copy from woocommerce plugin templates folder a file named content-product_cat.php inside the fresh created woocommerce folder in your active child theme (or theme).




The open/edit this copied content-product_cat.php template file.



Replace the following line:



do_action( 'woocommerce_shop_loop_subcategory_title', $category );


By this:



if( ! is_parent_category( $category, 'exterior-paving' ) ) {
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
}


Save, you are done. Now as you wished, all the brand titles only on the 'paving-brands' archive page will be removed.



This code is tested and fully functional.





ADDITION: Handling Multiple parent category slugs:



To handle multiple parent category slugs use the following instead (from an array of slugs):



function is_parent_category( $subcategory_term, $parent_category_term_slugs ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return in_array($parent_term->slug, $parent_category_term_slug ) ? true : false;
}


USAGE example:



// Reminder: $category is a WP_Term object
if ( is_parent_category( $category, array( 'clothing', 'posters' ) ) {
// Do something (matching subcategory)
} else {
// Do something else (no matching subcategory)
}





share|improve this answer


























  • Thank you so much, really appreciate the help.

    – Red Year
    Oct 3 '16 at 14:35
















1














Update - Nov 2018




The easiest way for that purpose is to make a custom conditional function that you will use in the concerned related template content-product_cat.php where the this subcategory title is hooked.




1) The conditional function



Here is that code:



function is_parent_category( $subcategory_term, $parent_category_term_slug ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return $parent_term->slug == $parent_category_term_slug ? true : false;
}


This code goes in function.php file of your active child theme (or theme) or also in any plugin file.





2) Overriding via your theme **content-product_cat.php WooCommerce template.**




If not done yet, inside your active child theme (or theme) create a woocommerce folder. Then copy from woocommerce plugin templates folder a file named content-product_cat.php inside the fresh created woocommerce folder in your active child theme (or theme).




The open/edit this copied content-product_cat.php template file.



Replace the following line:



do_action( 'woocommerce_shop_loop_subcategory_title', $category );


By this:



if( ! is_parent_category( $category, 'exterior-paving' ) ) {
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
}


Save, you are done. Now as you wished, all the brand titles only on the 'paving-brands' archive page will be removed.



This code is tested and fully functional.





ADDITION: Handling Multiple parent category slugs:



To handle multiple parent category slugs use the following instead (from an array of slugs):



function is_parent_category( $subcategory_term, $parent_category_term_slugs ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return in_array($parent_term->slug, $parent_category_term_slug ) ? true : false;
}


USAGE example:



// Reminder: $category is a WP_Term object
if ( is_parent_category( $category, array( 'clothing', 'posters' ) ) {
// Do something (matching subcategory)
} else {
// Do something else (no matching subcategory)
}





share|improve this answer


























  • Thank you so much, really appreciate the help.

    – Red Year
    Oct 3 '16 at 14:35














1












1








1







Update - Nov 2018




The easiest way for that purpose is to make a custom conditional function that you will use in the concerned related template content-product_cat.php where the this subcategory title is hooked.




1) The conditional function



Here is that code:



function is_parent_category( $subcategory_term, $parent_category_term_slug ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return $parent_term->slug == $parent_category_term_slug ? true : false;
}


This code goes in function.php file of your active child theme (or theme) or also in any plugin file.





2) Overriding via your theme **content-product_cat.php WooCommerce template.**




If not done yet, inside your active child theme (or theme) create a woocommerce folder. Then copy from woocommerce plugin templates folder a file named content-product_cat.php inside the fresh created woocommerce folder in your active child theme (or theme).




The open/edit this copied content-product_cat.php template file.



Replace the following line:



do_action( 'woocommerce_shop_loop_subcategory_title', $category );


By this:



if( ! is_parent_category( $category, 'exterior-paving' ) ) {
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
}


Save, you are done. Now as you wished, all the brand titles only on the 'paving-brands' archive page will be removed.



This code is tested and fully functional.





ADDITION: Handling Multiple parent category slugs:



To handle multiple parent category slugs use the following instead (from an array of slugs):



function is_parent_category( $subcategory_term, $parent_category_term_slugs ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return in_array($parent_term->slug, $parent_category_term_slug ) ? true : false;
}


USAGE example:



// Reminder: $category is a WP_Term object
if ( is_parent_category( $category, array( 'clothing', 'posters' ) ) {
// Do something (matching subcategory)
} else {
// Do something else (no matching subcategory)
}





share|improve this answer















Update - Nov 2018




The easiest way for that purpose is to make a custom conditional function that you will use in the concerned related template content-product_cat.php where the this subcategory title is hooked.




1) The conditional function



Here is that code:



function is_parent_category( $subcategory_term, $parent_category_term_slug ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return $parent_term->slug == $parent_category_term_slug ? true : false;
}


This code goes in function.php file of your active child theme (or theme) or also in any plugin file.





2) Overriding via your theme **content-product_cat.php WooCommerce template.**




If not done yet, inside your active child theme (or theme) create a woocommerce folder. Then copy from woocommerce plugin templates folder a file named content-product_cat.php inside the fresh created woocommerce folder in your active child theme (or theme).




The open/edit this copied content-product_cat.php template file.



Replace the following line:



do_action( 'woocommerce_shop_loop_subcategory_title', $category );


By this:



if( ! is_parent_category( $category, 'exterior-paving' ) ) {
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
}


Save, you are done. Now as you wished, all the brand titles only on the 'paving-brands' archive page will be removed.



This code is tested and fully functional.





ADDITION: Handling Multiple parent category slugs:



To handle multiple parent category slugs use the following instead (from an array of slugs):



function is_parent_category( $subcategory_term, $parent_category_term_slugs ) {
$parent_term = get_term( $subcategory_term->parent, $subcategory_term->taxonomy );
return in_array($parent_term->slug, $parent_category_term_slug ) ? true : false;
}


USAGE example:



// Reminder: $category is a WP_Term object
if ( is_parent_category( $category, array( 'clothing', 'posters' ) ) {
// Do something (matching subcategory)
} else {
// Do something else (no matching subcategory)
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 4:53

























answered Oct 3 '16 at 12:40









LoicTheAztecLoicTheAztec

98.4k1472114




98.4k1472114













  • Thank you so much, really appreciate the help.

    – Red Year
    Oct 3 '16 at 14:35



















  • Thank you so much, really appreciate the help.

    – Red Year
    Oct 3 '16 at 14:35

















Thank you so much, really appreciate the help.

– Red Year
Oct 3 '16 at 14:35





Thank you so much, really appreciate the help.

– Red Year
Oct 3 '16 at 14:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39831556%2fhide-sub-category-titles-on-single-parent-sub-category-archive-page-woocommerce%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly