diff --git a/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js b/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js index f91195ba56a..f5a7bdfe694 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js @@ -274,29 +274,36 @@ const AttributeFilterBlock = ( { [ pageUrl, attributeObject?.taxonomy ] ); + const onClickSubmit = ( isChecked ) => { + const query = updateAttributeFilter( + productAttributesQuery, + setProductAttributesQuery, + attributeObject, + getSelectedTerms( isChecked ), + blockAttributes.queryType === 'or' ? 'in' : 'and' + ); + + // This is for PHP rendered template filtering only. + if ( filteringForPhpTemplate ) { + redirectPageForPhpTemplate( query, isChecked.length === 0 ); + } + }; + const onSubmit = useCallback( ( isChecked ) => { if ( isEditor ) { return; } - const query = updateAttributeFilter( + updateAttributeFilter( productAttributesQuery, setProductAttributesQuery, attributeObject, getSelectedTerms( isChecked ), blockAttributes.queryType === 'or' ? 'in' : 'and' ); - - // This is for PHP rendered template filtering only. - if ( filteringForPhpTemplate && hasSetPhpFilterDefaults ) { - redirectPageForPhpTemplate( query, isChecked.length === 0 ); - } }, [ - hasSetPhpFilterDefaults, - filteringForPhpTemplate, - redirectPageForPhpTemplate, isEditor, productAttributesQuery, setProductAttributesQuery, @@ -588,7 +595,7 @@ const AttributeFilterBlock = ( { onSubmit( checked ) } + onClick={ () => onClickSubmit( checked ) } /> ) }