Hi,
Thank you for your kind words and for using the plugin!
You’re on the right track with your code. To ensure that the product types are correctly renamed on both the back-end and the front-end filters, you can use the following code snippet in your child theme’s functions.php
file. This code ensures that the product types are renamed everywhere they appear, including the front-end filters of WCAPF.
// Rename WC product types:
function custom_rename_product_types( $types ) {
$types['simple'] = __( 'Simple', 'wc-ajax-product-filter' );
$types['external'] = __( 'External', 'wc-ajax-product-filter' );
$types['grouped'] = __( 'Grouped', 'wc-ajax-product-filter' );
$types['variable'] = __( 'Variable', 'wc-ajax-product-filter' );
return $types;
}
add_filter( 'product_type_selector', 'custom_rename_product_types' );
add_filter( 'wcapf_taxonomy_terms', 'wcapf_rename_product_types_in_filter_options', 10, 2 );
/**
* Rename product types when showing in the filter options.
*
* @param array $terms The array of taxonomy terms.
* @param WCAPF_Field_Instance $field The field instance.
*
* @return array
*/
function wcapf_rename_product_types_in_filter_options( $terms, $field ) {
if ( 'taxonomy' === $field->type && 'product_type' === $field->taxonomy ) {
$new_terms = array();
foreach ( $terms as $_term ) {
$term = $_term;
if ( 'simple' === $term['slug'] ) {
$term['name'] = __( 'Simple', 'wc-ajax-product-filter' );
} elseif ( 'external' === $term['slug'] ) {
$term['name'] = __( 'External', 'wc-ajax-product-filter' );
} elseif ( 'grouped' === $term['slug'] ) {
$term['name'] = __( 'Grouped', 'wc-ajax-product-filter' );
} elseif ( 'variable' === $term['slug'] ) {
$term['name'] = __( 'Variable', 'wc-ajax-product-filter' );
}
$new_terms[] = $term;
}
return $new_terms;
}
return $terms;
}
add_filter( 'wcapf_active_taxonomy_filter_data', 'wcapf_rename_product_types_in_active_filters', 10, 2 );
/**
* Rename product types for active filters.
*
* @param array $filter_data The filter data.
* @param WCAPF_Field_Instance $field_instance The field instance.
*
* @return array
*/
function wcapf_rename_product_types_in_active_filters( $filter_data, $field_instance ) {
if ( 'taxonomy' === $field_instance->type && 'product_type' === $field_instance->taxonomy ) {
$new_filter_data = array();
foreach ( $filter_data as $term_id => $term_name ) {
$new_name = $term_name;
if ( 'Blue' === $term_name ) {
$new_name = 'hello';
}
if ( 'simple' === $term_name ) {
$new_name = __( 'Simple', 'wc-ajax-product-filter' );
} elseif ( 'external' === $term_name ) {
$new_name = __( 'External', 'wc-ajax-product-filter' );
} elseif ( 'grouped' === $term_name ) {
$new_name = __( 'Grouped', 'wc-ajax-product-filter' );
} elseif ( 'variable' === $term_name ) {
$new_name = __( 'Variable', 'wc-ajax-product-filter' );
}
$new_filter_data[ $term_id ] = $new_name;
}
return $new_filter_data;
}
return $filter_data;
}
If you have any further questions or need additional assistance, feel free to ask!