Skip to content

Instantly share code, notes, and snippets.

@agusmu
Last active May 1, 2024 13:27
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save agusmu/eaedc6f63edbdaf237f2 to your computer and use it in GitHub Desktop.
Save agusmu/eaedc6f63edbdaf237f2 to your computer and use it in GitHub Desktop.
Customize WooCommerce Categories & Tags Label
/* Customize Product Categories Labels */
add_filter( 'woocommerce_taxonomy_args_product_cat', 'custom_wc_taxonomy_args_product_cat' );
function custom_wc_taxonomy_args_product_cat( $args ) {
$args['label'] = __( 'Product Categories', 'woocommerce' );
$args['labels'] = array(
'name' => __( 'Product Categories', 'woocommerce' ),
'singular_name' => __( 'Product Category', 'woocommerce' ),
'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Product Categories', 'woocommerce' ),
'all_items' => __( 'All Product Categories', 'woocommerce' ),
'parent_item' => __( 'Parent Product Category', 'woocommerce' ),
'parent_item_colon' => __( 'Parent Product Category:', 'woocommerce' ),
'edit_item' => __( 'Edit Product Category', 'woocommerce' ),
'update_item' => __( 'Update Product Category', 'woocommerce' ),
'add_new_item' => __( 'Add New Product Category', 'woocommerce' ),
'new_item_name' => __( 'New Product Category Name', 'woocommerce' )
);
return $args;
}
add_filter( 'woocommerce_taxonomy_args_product_cat', 'custom_wc_taxonomy_label_product_cat' );
function custom_wc_taxonomy_label_product_cat( $args ) {
$args['label'] = 'My Categories';
$args['labels'] = array(
'name' => 'My Categories',
'singular_name' => 'My Categories',
'menu_name' => 'My Categories'
);
return $args;
}
add_action( 'init', 'custom_wc_product_cat_label' );
function custom_wc_product_cat_label() {
global $wp_taxonomies;
if ( isset( $wp_taxonomies['product_cat'] ) ) {
$cat = $wp_taxonomies['product_cat'];
$cat->label = 'My Categories';
$cat->labels->singular_name = 'My Category';
$cat->labels->name = $cat->label;
$cat->labels->menu_name = $cat->label;
}
}
/* Customize Product Tags Labels */
add_filter( 'woocommerce_taxonomy_args_product_tag', 'custom_wc_taxonomy_args_product_tag' );
function custom_wc_taxonomy_args_product_tag( $args ) {
$args['label'] = __( 'Product Tags', 'woocommerce' );
$args['labels'] = array(
'name' => __( 'Product Tags', 'woocommerce' ),
'singular_name' => __( 'Product Tag', 'woocommerce' ),
'menu_name' => _x( 'Tags', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Product Tags', 'woocommerce' ),
'all_items' => __( 'All Product Tags', 'woocommerce' ),
'parent_item' => __( 'Parent Product Tag', 'woocommerce' ),
'parent_item_colon' => __( 'Parent Product Tag:', 'woocommerce' ),
'edit_item' => __( 'Edit Product Tag', 'woocommerce' ),
'update_item' => __( 'Update Product Tag', 'woocommerce' ),
'add_new_item' => __( 'Add New Product Tag', 'woocommerce' ),
'new_item_name' => __( 'New Product Tag Name', 'woocommerce' )
);
return $args;
}
add_filter( 'woocommerce_taxonomy_args_product_tag', 'custom_wc_taxonomy_label_product_tag' );
function custom_wc_taxonomy_label_product_tag( $args ) {
$args['label'] = 'My Tag';
$args['labels'] = array(
'name' => 'My Tag',
'singular_name' => 'My Tag',
'menu_name' => 'My Tag'
);
return $args;
}
add_action( 'init', 'custom_wc_product_tag_label' );
function custom_wc_product_tag_label() {
global $wp_taxonomies;
if ( isset( $wp_taxonomies['product_tag'] ) ) {
$cat = $wp_taxonomies['product_tag'];
$cat->label = 'My Tag';
$cat->labels->singular_name = 'My Tag';
$cat->labels->name = $cat->label;
$cat->labels->menu_name = $cat->label;
}
}
@Back2Front
Copy link

Very nice to customise the Wordpress admin for users.
I found this extra snippet useful to then display on the front end:

`// changing word 'Categories' to 'Locations' on single product page

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 = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );

?>

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>
get_categories( ', ', '' . _n( '', '', $cat_count, 'woocommerce' ) . ' ', '.' ); ?> get_tags( ', ', '' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.' ); ?>

@xturgorex
Copy link

Very nice! Thank you. I used functions2a to change Tags to Product tags. I have created a custom content type that will allow posts to be tagged with both the woo product tags and use the wordpress post tags and this will make it much less confusing for the content creators. Thanks again.

@JordiSanchezHinojosa
Copy link

Fantastic! I use the functions1a.php and work great in the back end. It's possible that it works in the front end too?.
I use a plugin for make some ajax filters to products and they don't change the name at the title. Many thanks.
Perhaps I need to translate some more label?

@JordiSanchezHinojosa
Copy link

I found it!

add_filter(  'gettext',  'change_post_to_myname'  );
add_filter(  'ngettext',  'change_post_to_myname'  );

function change_post_to_myname( $translated ) {
     $translated = str_ireplace(  'Categories',  'My New Name' ,  $translated );  // ireplace is PHP5 only
     return $translated;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment