Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the amount of terms shown in attributes page #33962

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Reduce the amount of terms shown in attributes page
53 changes: 43 additions & 10 deletions plugins/woocommerce/includes/admin/class-wc-admin-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,16 @@ public static function add_attribute() {
<tbody>
<?php
$attribute_taxonomies = wc_get_attribute_taxonomies();
if ( $attribute_taxonomies ) :
if ( $attribute_taxonomies ) {
/**
* Filters the maximum number of terms that will be displayed for each taxonomy in the Attributes page.
*
* @param int @default_max_terms_to_display Default value.
* @returns int Actual value to use, may be zero.
*
* @since 6.9.0
*/
$max_terms_to_display = apply_filters( 'woocommerce_max_terms_displayed_in_attributes_page', 100 );
foreach ( $attribute_taxonomies as $tax ) :
?>
<tr>
Expand Down Expand Up @@ -353,30 +362,54 @@ public static function add_attribute() {
$taxonomy = wc_attribute_taxonomy_name( $tax->attribute_name );

if ( taxonomy_exists( $taxonomy ) ) {
$terms = get_terms( $taxonomy, 'hide_empty=0' );
$terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) );
if ( $terms_string ) {
$total_count = (int) get_terms(
array(
'taxonomy' => $taxonomy,
'fields' => 'count',
'hide_empty' => false,
)
);
if ( 0 === $total_count ) {
echo '<span class="na">&ndash;</span>';
} elseif ( $max_terms_to_display > 0 ) {
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'number' => $max_terms_to_display,
'fields' => 'names',
'hide_empty' => false,
)
);
$terms_string = implode( ', ', $terms );
if ( $total_count > $max_terms_to_display ) {
$remaining = $total_count - $max_terms_to_display;
/* translators: 1: Comma-separated terms list, 2: how many terms are hidden */
$terms_string = sprintf( __( '%1$s... (%2$s more)', 'woocommerce' ), $terms_string, $remaining );
}
echo esc_html( $terms_string );
} elseif ( 1 === $total_count ) {
echo esc_html( __( '1 term', 'woocommerce' ) );
} else {
echo '<span class="na">&ndash;</span>';
/* translators: %s: Total count of terms available for the attribute */
echo esc_html( sprintf( __( '%s terms', 'woocommerce' ), $total_count ) );
}
} else {
echo '<span class="na">&ndash;</span>';
echo '<span class="na">&ndash;</span><br />';
}
?>
<br /><a href="edit-tags.php?taxonomy=<?php echo esc_attr( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&amp;post_type=product" class="configure-terms"><?php esc_html_e( 'Configure terms', 'woocommerce' ); ?></a>
</td>
</tr>
<?php
endforeach;
else :
?>
} else {
?>
<tr>
<td colspan="6"><?php esc_html_e( 'No attributes currently exist.', 'woocommerce' ); ?></td>
</tr>
<?php
endif;
?>
}
?>
</tbody>
</table>
</div>
Expand Down