Home » WooCommerce: Hide Category & Tag @ Single Product Page

WooCommerce: Hide Category & Tag @ Single Product Page

by Tutor Aspire

SKU, Category list and Tag list on the WooCommerce single product page are called “product meta”. We already saw how to hide just the SKU (while leaving Cats and Tags there), so in this “episode” we will study how to do the opposite i.e. keeping the SKU there while hiding Cats and/or Tags.

If you are a developer, you’d think there were a specific WooCommerce “filter” for this, but there is not. So, we have to first remove the whole “product meta” block and then add back the info we want (just the Cats, for example). If you’re not a dev – not to worry – just copy paste one of the snippets below in your functions.php and magic will happen. Enjoy!

We’re looking at the “Product Meta” section on the single product page. Our goal is to hide categories and tags and leave SKU where it is now.

PHP Snippet 1: Hide “SKU” & “Category:__” & “Tag:__” @ WooCommerce Single Product Page

Basically, in here we go and remove the whole “Product Meta” block. And thankfully, it’s just 1 line of code.

If you want to add back just the SKU, just the Cats or just the Tags, use snippet 2, 3 or 4 together with this one.

/**
 * @snippet       Hide SKU, Cats, Tags @ Single Product Page - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WC 3.8
 * @donate $9     https://www.tutoraspire.com
 */
  
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

PHP Snippet 2: Show “SKU”Again @ WooCommerce Single Product Page

This is equivalent to saying “Hide Categories and Tags” from product meta. Basically after removing the whole product meta block, we’re readding the SKU.

/**
 * @snippet       Show SKU Again @ Single Product Page - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WC 3.8
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_single_product_summary', 'tutoraspire_show_sku_again_single_product', 40 );

function tutoraspire_show_sku_again_single_product() {
   global $product;
   ?>
   
get_sku() || $product->is_type( 'variable' ) ) ) : ?> get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' ); ?>

PHP Snippet 3: Show “Categories:” Again @ WooCommerce Single Product Page

/**
 * @snippet       Show Categories Again @ Single Product Page - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WC 3.8
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_single_product_summary', 'tutoraspire_show_cats_again_single_product', 40 );

function tutoraspire_show_cats_again_single_product() {
   global $product;
   ?>
   
get_id(), ', ', '' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '' ); ?>

PHP Snippet 4: Show “Tags:” Again @ WooCommerce Single Product Page

/**
 * @snippet       Show Tags Again @ Single Product Page - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WC 3.8
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_single_product_summary', 'tutoraspire_show_tags_again_single_product', 40 );

function tutoraspire_show_tags_again_single_product() {
   global $product;
   ?>
   
get_id(), ', ', '' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'woocommerce' ) . ' ', '' ); ?>

You may also like