Fix variation name in WC Analytics Variations report (#49440)

* Show "Any [ATTRIBUTE_NAME]" for variation product if attribute is empty

Like that in the product variation edit page:
35a0ee2e8a/plugins/woocommerce/includes/admin/meta-boxes/views/html-variation-admin.php (L36)

* Add changelog
This commit is contained in:
Ian Yu-Hsun Lin 2024-07-15 16:55:06 +08:00 committed by GitHub
parent e1b314229c
commit c269a86efc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { __, sprintf } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url'; import { addQueryArgs } from '@wordpress/url';
import apiFetch from '@wordpress/api-fetch'; import apiFetch from '@wordpress/api-fetch';
import { identity } from 'lodash'; import { identity } from 'lodash';
@ -106,7 +107,19 @@ export function getVariationName( { attributes, name } ) {
} }
const attributeList = ( attributes || [] ) const attributeList = ( attributes || [] )
.map( ( { option } ) => option ) .map( ( { name: attributeName, option } ) => {
if ( ! option ) {
attributeName =
attributeName.charAt( 0 ).toUpperCase() +
attributeName.slice( 1 );
option = sprintf(
// translators: %s: the attribute name.
__( 'Any %s', 'woocommerce' ),
attributeName
);
}
return option;
} )
.join( ', ' ); .join( ', ' );
return attributeList ? name + separator + attributeList : name; return attributeList ? name + separator + attributeList : name;

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix variation name in analytics variations report