Skip to content

Instantly share code, notes, and snippets.

@agusmu
Last active May 1, 2024 13:27
Show Gist options
  • 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;
}
}
@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