2

I'm trying to remove the word Category from the product page.

enter image description here

As far as I know the code that displays that is woocommerce_template_single_meta located into content-single-product.php file:

<?php
        /**
         * woocommerce_single_product_summary hook
         *
         * @hooked woocommerce_template_single_title - 5
         * @hooked woocommerce_template_single_rating - 10
         * @hooked woocommerce_template_single_price - 10
         * @hooked woocommerce_template_single_excerpt - 20
         * @hooked woocommerce_template_single_add_to_cart - 30
         * @hooked woocommerce_template_single_meta - 40
         * @hooked woocommerce_template_single_sharing - 50
         */
        do_action( 'woocommerce_single_product_summary' );
    ?>

I would like to know how I can modify and customize this hook, so I would be able to place it where I want and use my own styles.

1 Answer 1

5

This will definitely remove the word "category". Add this code in functions.php.As you already know woocommerce_template_single_meta is the hook responsible for meta information of the single-product.

File is present in /woocommerce/templates/single-product/meta.php. Either you can use the following code to edit the HTML of meta.php or you can copy the file meta.php to themes/your-theme/woocommerce/single-product/meta.php. Then edit the meta.php as you want it to be.

<?php

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta_remove_category', 40 );

function woocommerce_template_single_meta_remove_category(){    

    global $post, $product;

    $cat_count = ( !empty( $cats ) && ! is_wp_error( $cats ) ) ? 
count($cats) : 0;

    $tag_count = ( !empty( $tags ) && ! is_wp_error( $tags ) ) ? count($tags) : 0;

?>
<div class="product_meta">

  <?php do_action( 'woocommerce_product_meta_start' ); ?>

  <?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
     
    <span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>

  <?php endif; ?>

  <?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( '', '', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>

  <?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' ); ?>

  <?php do_action( 'woocommerce_product_meta_end' ); ?>

</div>

<?php
}
8
  • Thank you, it removes everything, but I'm trying to remove only the word. Jul 16, 2015 at 15:37
  • which theme , you are using
    – terminator
    Jul 16, 2015 at 15:43
  • Custom theme I designed, based on bootstrap and underscores Jul 16, 2015 at 15:52
  • @Kevin I have edited the code above this will definitly do what you are trying to achieve
    – terminator
    Jul 16, 2015 at 16:22
  • Thank you @terminator, it worked. I must say that the explanation is a bit confusing, I just replaced from <div class="product_meta">... to the closing div in the meta.php file. When adding the code in Functions.php it doesn't work. Jul 17, 2015 at 8:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.