Hide `Variations` section when it is empty (#36202)
* Add changelog * Hide Variations section when it is empty * Fix hiding variations * Remove `totalCount const Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
parent
891ecb7efb
commit
78002eac9c
|
@ -3,7 +3,8 @@
|
|||
*/
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { recordEvent } from '@woocommerce/tracks';
|
||||
import { Link } from '@woocommerce/components';
|
||||
import { Link, useFormContext } from '@woocommerce/components';
|
||||
import { Product, ProductAttribute } from '@woocommerce/data';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -12,6 +13,28 @@ import { ProductSectionLayout } from '../layout/product-section-layout';
|
|||
import { Variations } from '../fields/variations';
|
||||
|
||||
export const ProductVariationsSection: React.FC = () => {
|
||||
const {
|
||||
getInputProps,
|
||||
values: { id: productId },
|
||||
} = useFormContext< Product >();
|
||||
|
||||
const { value: attributes }: { value: ProductAttribute[] } = getInputProps(
|
||||
'attributes',
|
||||
{
|
||||
productId,
|
||||
}
|
||||
);
|
||||
|
||||
const options = attributes
|
||||
? attributes.filter(
|
||||
( attribute: ProductAttribute ) => attribute.variation
|
||||
)
|
||||
: [];
|
||||
|
||||
if ( options.length === 0 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ProductSectionLayout
|
||||
title={ __( 'Variations', 'woocommerce' ) }
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Hide Variations section when it is empty
|
Loading…
Reference in New Issue