Fix: Product Collection block should respects 'Out of stock visibility' setting (#47537)

* Fix: Ensure Product Collection Block Respects "Hide Out of Stock Items" Setting

- Added logic to include the "Out of stock visibility" setting in the Product Collection block.
- Modified `ProductTemplateEdit` component to use the `getDefaultStockStatuses` function.
- Ensured that out-of-stock products are hidden in the Product Collection block when the "Hide out of stock items from the catalog" option is enabled.

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Manish Menaria 2024-05-21 10:50:05 +05:30 committed by GitHub
parent 4374617d43
commit 3a3a386e34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import type { BlockEditProps, BlockInstance } from '@wordpress/blocks';
*/ */
import { useGetLocation, useProductCollectionQueryContext } from './utils'; import { useGetLocation, useProductCollectionQueryContext } from './utils';
import './editor.scss'; import './editor.scss';
import { getDefaultStockStatuses } from '../product-collection/constants';
const DEFAULT_QUERY_CONTEXT_ATTRIBUTES = [ 'collection' ]; const DEFAULT_QUERY_CONTEXT_ATTRIBUTES = [ 'collection' ];
@ -251,6 +252,14 @@ const ProductTemplateEdit = (
location, location,
productCollectionQueryContext, productCollectionQueryContext,
previewState: __privateProductCollectionPreviewState, previewState: __privateProductCollectionPreviewState,
/**
* Use value of "Out of stock visibility" setting to determine
* which stock statuses to include if inherit query
* from template is true.
*/
...( inherit && {
woocommerceStockStatus: getDefaultStockStatuses(),
} ),
} ), } ),
blocks: getBlocks( clientId ), blocks: getBlocks( clientId ),
}; };

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix: Product Collection Block Respects 'Out of stock visibility' Setting