Commit c0d254b17e5 for woocommerce
commit c0d254b17e5cc3ce746c4d4dc0cd9e5b07243a7f
Author: Devanshi Joshi <86941664+devanshijoshi9@users.noreply.github.com>
Date: Wed Sep 16 18:22:15 2026 +0530
[Issue - #57056]Remove isDescendentOf attributes which are set on editor page load (#66287)
* Fix: Remove isdescendentof attributes from the all products block
* Add changefile(s) from automation for the following project(s): woocommerce
* Fix: Resolve coderabbitai feedbacks
* Remove save import line from product blocks where it's not relying on saved save file
* Fix: change the PR reference in product price deprecated file
* Fix: Remove unused isDescedent* attributes from rating counter block
* Add changefile(s) from automation for the following project(s): woocommerce
* Fix: Rename deprecated.ts to deprecated.tsx for button block
* Fix: Remove unused isDescendentOf attributes from types.ts
* Fix: Remove unused isDescendentOf props from block components
* Fix: Remove additional unused isDescendentOf props from rating-counter and rating-stars
* Fix: Remove isDescendentOf attributes from sale-badge block.json and add missing deprecated attribute
* Fix: Remove unused isDescendentOf prop calculations and imports from product-elements
* Fix missing Sale Badge in Product Collection and address linting issues
* Fix remaining lint errors in product-elements blocks
* Fix review count always showing for Product Rating in Product Collection
isDescendentOfQueryLoop was computed but never passed to Block, so
showReviewCount always evaluated to true in the editor. Restore the
prop pass without reintroducing the removed setAttributes persistence.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Remove remaining product block ancestry attributes
* Add changelog entries for product block ancestry cleanup
* Remove added image sizing props from tests
* Remove the singleProduct context dependency from rating blocks
* Use the global product to determine rating review links
* Remove rating context regression tests
* fix logic
* fix migration
* fix migration
* clean up tests and template
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
diff --git a/docs/block-development/reference/block-references.md b/docs/block-development/reference/block-references.md
index 94524b66a08..65b54309cc0 100644
--- a/docs/block-development/reference/block-references.md
+++ b/docs/block-development/reference/block-references.md
@@ -27,7 +27,7 @@ Display a call to action button which either adds the product to the cart, or li
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/all-products, woocommerce/single-product, core/post-template, woocommerce/product-template
- **Supports:** align (full, wide), color (background, text, ~~link~~), email, interactivity, spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
-- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, productId, textAlign, width
+- **Attributes:** productId, textAlign, width
## Product Image - woocommerce/product-image
@@ -37,7 +37,7 @@ Display the main product image.
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/all-products, woocommerce/single-product, woocommerce/product-template, core/post-template
- **Supports:** dimensions (aspectRatio), email, interactivity (clientNavigation), spacing (margin, padding), typography (fontSize), ~~html~~
-- **Attributes:** aspectRatio, height, imageSizing, isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, productId, saleBadgeAlign, scale, showProductLink, showSaleBadge, width
+- **Attributes:** aspectRatio, height, imageSizing, productId, saleBadgeAlign, scale, showProductLink, showSaleBadge, width
## Product Price - woocommerce/product-price
@@ -47,7 +47,7 @@ Display the price of a product.
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/all-products, woocommerce/featured-product, woocommerce/single-product, woocommerce/product-template, core/post-template
- **Supports:** color (background, text, ~~link~~), email, interactivity, spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
-- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, productId, textAlign
+- **Attributes:** productId, textAlign
## Product Image Gallery - woocommerce/product-image-gallery
@@ -73,7 +73,7 @@ Display the average rating of a product.
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/all-products, woocommerce/single-product, woocommerce/product-template, core/post-template
- **Supports:** color (text, ~~background~~, ~~link~~), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize)
-- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, productId, textAlign
+- **Attributes:** productId, textAlign
## Product Rating Counter - woocommerce/product-rating-counter
@@ -83,7 +83,7 @@ Display the review count of a product
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/single-product
- **Supports:** color (link, ~~background~~, ~~text~~), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize), ~~inserter~~
-- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, productId, textAlign
+- **Attributes:** productId, textAlign
## Product Rating Stars - woocommerce/product-rating-stars
@@ -93,7 +93,7 @@ Display the average rating of a product with stars
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/single-product
- **Supports:** color (text, ~~background~~, ~~link~~), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize), ~~inserter~~
-- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, productId, textAlign
+- **Attributes:** productId, textAlign
## Related Products - woocommerce/related-products
@@ -111,7 +111,7 @@ Displays an on-sale badge if the product is on-sale.
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/single-product, woocommerce/product-template, core/post-template, woocommerce/product-gallery
- **Supports:** align, color (background, gradients, text, ~~link~~), email, interactivity (clientNavigation), spacing (margin), typography (fontSize, lineHeight), ~~html~~
-- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, productId
+- **Attributes:** productId
## Product SKU - woocommerce/product-sku
@@ -141,7 +141,7 @@ Display a short description about a product.
- **Category:** woocommerce-product-elements
- **Ancestor:** woocommerce/all-products, woocommerce/featured-product, woocommerce/single-product, woocommerce/product-template, core/post-template
- **Supports:** color (background, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign)
-- **Attributes:** isDescendantOfAllProducts, isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, linkText, productId, showDescriptionIfEmpty, showLink, summaryLength
+- **Attributes:** isDescendantOfAllProducts, linkText, productId, showDescriptionIfEmpty, showLink, summaryLength
## Product Title - woocommerce/product-title
diff --git a/plugins/woocommerce/changelog/66287-fix-57056-remove-isdescendentof-attrs b/plugins/woocommerce/changelog/66287-fix-57056-remove-isdescendentof-attrs
new file mode 100644
index 00000000000..1d0dacadbe3
--- /dev/null
+++ b/plugins/woocommerce/changelog/66287-fix-57056-remove-isdescendentof-attrs
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Clean up legacy `isDescendentOf` attributes from product element blocks and preserve backward compatibility with deprecated block definitions.
diff --git a/plugins/woocommerce/changelog/fix-product-block-ancestry-review b/plugins/woocommerce/changelog/fix-product-block-ancestry-review
new file mode 100644
index 00000000000..33921663f5c
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-product-block-ancestry-review
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Preserve product rating review links and remove obsolete attributes from product block templates.
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/block.json
index 1baa9010ad6..3cf188450ac 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/block.json
@@ -23,14 +23,6 @@
},
"width": {
"type": "number"
- },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfQueryLoop": {
- "type": "boolean",
- "default": false
}
},
"supports": {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/deprecated.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/deprecated.tsx
new file mode 100644
index 00000000000..8eb4e3d7dee
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/deprecated.tsx
@@ -0,0 +1,59 @@
+/**
+ * Internal dependencies
+ */
+import { useBlockProps } from '@wordpress/block-editor';
+import clsx from 'clsx';
+import metadata from './block.json';
+import { BlockAttributes } from './types';
+
+const { attributes: blockAttributes } = metadata;
+
+interface V1Attributes extends BlockAttributes {
+ isDescendentOfQueryLoop?: boolean;
+ isDescendentOfSingleProductBlock?: boolean;
+}
+
+const save = ( {
+ attributes,
+ innerBlocks,
+}: {
+ attributes: V1Attributes;
+ innerBlocks?: unknown[];
+} ) => {
+ if (
+ attributes.isDescendentOfQueryLoop ||
+ attributes.isDescendentOfSingleProductBlock ||
+ ! innerBlocks ||
+ innerBlocks?.length === 0
+ ) {
+ return null;
+ }
+
+ return (
+ <div
+ { ...useBlockProps.save( {
+ className: clsx( 'is-loading', attributes.className, {
+ [ `has-custom-width wp-block-button__width-${ attributes.width }` ]:
+ attributes.width,
+ } ),
+ } ) }
+ />
+ );
+};
+
+const v1 = {
+ attributes: {
+ ...blockAttributes,
+ isDescendentOfQueryLoop: { type: 'boolean', default: false },
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
+ },
+ save,
+ apiVersion: 3,
+};
+
+const deprecated = [ v1 ];
+
+export default deprecated;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/edit.tsx
index 86a7ec0bab0..e9d01cf2a42 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/edit.tsx
@@ -10,7 +10,6 @@ import {
InspectorControls,
} from '@wordpress/block-editor';
import type { BlockEditProps } from '@wordpress/blocks';
-import { useEffect } from '@wordpress/element';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
import { useProduct } from '@woocommerce/entities';
import {
@@ -90,13 +89,7 @@ const Edit = ( {
} ): JSX.Element => {
const blockProps = useBlockProps();
const { product } = useProduct( context?.postId );
- const isDescendentOfQueryLoop = Number.isFinite( context?.queryId );
const { width } = attributes;
-
- useEffect(
- () => setAttributes( { isDescendentOfQueryLoop } ),
- [ setAttributes, isDescendentOfQueryLoop ]
- );
return (
<>
<BlockControls>
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/index.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/index.tsx
index d3180f024b0..8e595e38798 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/index.tsx
@@ -8,7 +8,7 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import edit from './edit';
-import save from './save';
+import deprecated from './deprecated';
import metadata from './block.json';
// @ts-expect-error: `metadata` currently does not have a type definition in WordPress core
@@ -26,5 +26,6 @@ registerBlockType( metadata, {
...metadata.attributes,
},
edit,
- save,
+ save: () => null,
+ deprecated,
} );
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/save.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/save.tsx
deleted file mode 100644
index 663922ba93c..00000000000
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/save.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * External dependencies
- */
-import { useBlockProps } from '@wordpress/block-editor';
-import clsx from 'clsx';
-
-/**
- * Internal dependencies
- */
-import { BlockAttributes } from './types';
-
-type Props = {
- attributes: BlockAttributes;
-};
-
-const Save = ( { attributes, innerBlocks }: Props ): JSX.Element | null => {
- if (
- attributes.isDescendentOfQueryLoop ||
- attributes.isDescendentOfSingleProductBlock ||
- ! innerBlocks ||
- innerBlocks?.length === 0
- ) {
- return null;
- }
-
- return (
- <div
- { ...useBlockProps.save( {
- className: clsx( 'is-loading', attributes.className, {
- [ `has-custom-width wp-block-button__width-${ attributes.width }` ]:
- attributes.width,
- } ),
- } ) }
- />
- );
-};
-
-export default Save;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/types.ts
index cdd0c2ff29d..372ba28a9dd 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/button/types.ts
@@ -14,8 +14,6 @@ interface WithStyle {
export interface BlockAttributes {
className?: string | undefined;
textAlign?: string | undefined;
- isDescendentOfQueryLoop?: boolean | undefined;
- isDescendentOfSingleProductBlock?: boolean | undefined;
width?: number | undefined;
// eslint-disable-next-line @typescript-eslint/naming-convention
'woocommerce/isDescendantOfAddToCartWithOptions'?: boolean | undefined;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/block.json
index 6cd3d2a1b8f..f7475a39103 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/block.json
@@ -9,11 +9,6 @@
"saleBadgeAlign": { "type": "string", "default": "right" },
"imageSizing": { "type": "string", "default": "single" },
"productId": { "type": "number", "default": 0 },
- "isDescendentOfQueryLoop": { "type": "boolean", "default": false },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
"width": { "type": "string" },
"height": { "type": "string" },
"scale": { "type": "string", "default": "cover" },
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/deprecated.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/deprecated.tsx
index f8638bedf71..7c7e99e3ff2 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/deprecated.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/deprecated.tsx
@@ -14,7 +14,14 @@ import { isTryingToDisplayLegacySaleBadge } from './utils';
// In v2, we're migrating the `showSaleBadge` attribute to an inner block.
const v1 = {
save,
- attributes: metadata.attributes,
+ attributes: {
+ ...metadata.attributes,
+ isDescendentOfQueryLoop: { type: 'boolean', default: false },
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
+ },
isEligible: ( { showSaleBadge }: BlockAttributes ) =>
isTryingToDisplayLegacySaleBadge( showSaleBadge ),
migrate: ( attributes: BlockAttributes ) => {
@@ -40,6 +47,20 @@ const v1 = {
],
];
},
+ apiVersion: 3,
+};
+
+const v2 = {
+ save,
+ attributes: {
+ ...metadata.attributes,
+ isDescendentOfQueryLoop: { type: 'boolean', default: false },
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
+ },
+ apiVersion: 3,
};
-export default [ v1 ];
+export default [ v2, v1 ];
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/edit.tsx
index 52450e466c9..3adba3f0908 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/edit.tsx
@@ -76,28 +76,25 @@ const Edit = ( {
blockClientId: blockProps?.id,
} );
+ const showAllControls =
+ isDescendentOfQueryLoop || isDescendentOfSingleProductBlock;
+ const showSaleBadge = showAllControls ? false : attributes.showSaleBadge;
+
+ // Persist this so PHP doesn't render the legacy sale badge alongside the inner block.
useEffect( () => {
- if ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- showSaleBadge: false,
- } );
- } else {
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- } );
+ if (
+ ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) &&
+ attributes.showSaleBadge !== false
+ ) {
+ setAttributes( { showSaleBadge: false } );
}
}, [
isDescendentOfQueryLoop,
isDescendentOfSingleProductBlock,
+ attributes.showSaleBadge,
setAttributes,
] );
- const showAllControls =
- isDescendentOfQueryLoop || isDescendentOfSingleProductBlock;
-
const innerBlockProps = useInnerBlocksProps(
{
className: 'wc-block-components-product-image__inner-container',
@@ -171,6 +168,7 @@ const Edit = ( {
) }
<Block
{ ...{ ...attributes, ...context } }
+ showSaleBadge={ showSaleBadge }
isAdmin={ true }
product={ product }
isResolving={ isResolving }
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/index.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/index.tsx
index 190329082a5..6db5b001f5a 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/index.tsx
@@ -1,14 +1,12 @@
/**
* External dependencies
*/
-import clsx from 'clsx';
-import { InnerBlocks } from '@wordpress/block-editor';
import { registerBlockType } from '@wordpress/blocks';
+import { InnerBlocks } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
-import { BlockAttributes } from './types';
import deprecated from './deprecated';
import edit from './edit';
import { BLOCK_ICON as icon } from './constants';
@@ -18,13 +16,7 @@ registerBlockType( metadata, {
deprecated,
icon,
edit,
- save: ( { attributes }: { attributes: BlockAttributes } ) => {
- if (
- attributes.isDescendentOfQueryLoop ||
- attributes.isDescendentOfSingleProductBlock
- ) {
- return <InnerBlocks.Content />;
- }
- return <div className={ clsx( 'is-loading', attributes.className ) } />;
- },
+ // The `woocommerce/product-sale-badge` inner block needs to persist —
+ // returning `null` would drop it from the saved content.
+ save: () => <InnerBlocks.Content />,
} );
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.tsx
index 404df4ed43b..113ccab9b8d 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.tsx
@@ -166,7 +166,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.SINGLE }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -200,7 +199,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.SINGLE }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -233,7 +231,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.SINGLE }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -263,7 +260,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.SINGLE }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -291,7 +287,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.SINGLE }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -318,7 +313,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.THUMBNAIL }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -346,7 +340,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.THUMBNAIL }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
@@ -372,7 +365,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.THUMBNAIL }
- isDescendentOfQueryLoop={ false }
aspectRatio="3/5"
/>
</ProductDataContextProvider>
@@ -406,7 +398,6 @@ describe( 'Product Image Block', () => {
showSaleBadge={ false }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.THUMBNAIL }
- isDescendentOfQueryLoop={ false }
/>
</ProductDataContextProvider>
);
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/types.ts
index 06c05a9b04f..3159b578d7c 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/image/types.ts
@@ -29,10 +29,7 @@ export interface BlockAttributes {
saleBadgeAlign: 'left' | 'center' | 'right';
// Size of image to use.
imageSizing: ImageSizing;
- // Whether or not the block is within the context of a Query Loop Block.
- isDescendentOfQueryLoop: boolean;
- // Whether or not the block is within the context of a Single Product Block.
- isDescendentOfSingleProductBlock: boolean;
+
// Height of the image.
height?: string;
// Width of the image.
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.json
index 216262498a4..5cfbf4d5bf4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.json
@@ -5,16 +5,7 @@
"category": "woocommerce-product-elements",
"attributes": {
"productId": { "type": "number", "default": 0 },
- "isDescendentOfQueryLoop": { "type": "boolean", "default": false },
- "textAlign": { "type": "string", "default": "" },
- "isDescendentOfSingleProductTemplate": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- }
+ "textAlign": { "type": "string", "default": "" }
},
"usesContext": [ "query", "queryId", "postId" ],
"keywords": [ "WooCommerce" ],
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.tsx
index 66778cc98f0..53179b18f3a 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/block.tsx
@@ -25,6 +25,7 @@ type Props = BlockAttributes &
HTMLAttributes< HTMLDivElement > & {
isAdmin: boolean;
isExperimentalWcRestApiV4Enabled: boolean;
+ isDescendentOfSingleProductTemplate: boolean;
product: ProductResponseItem | ProductEntityResponse | undefined;
};
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/deprecated.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/deprecated.ts
new file mode 100644
index 00000000000..68b62f280c5
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/deprecated.ts
@@ -0,0 +1,29 @@
+/**
+ * Internal dependencies
+ */
+import metadata from './block.json';
+import save from '../save';
+
+const { attributes: blockAttributes } = metadata;
+
+// In https://github.com/woocommerce/woocommerce/pull/66287, the `isDescendentOf*` attributes were removed from editor-load updates and block attributes.
+const v1 = {
+ attributes: {
+ ...blockAttributes,
+ isDescendentOfQueryLoop: { type: 'boolean', default: false },
+ isDescendentOfSingleProductTemplate: {
+ type: 'boolean',
+ default: false,
+ },
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
+ },
+ save,
+ apiVersion: 3,
+};
+
+const deprecated = [ v1 ];
+
+export default deprecated;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/edit.tsx
index 3de78f314eb..f1336d443ab 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/edit.tsx
@@ -6,7 +6,6 @@ import {
BlockControls,
useBlockProps,
} from '@wordpress/block-editor';
-import { useEffect } from '@wordpress/element';
import type { BlockAlignment } from '@wordpress/blocks';
import { isExperimentalWcRestApiV4Enabled } from '@woocommerce/block-settings';
import { useProduct } from '@woocommerce/entities';
@@ -26,13 +25,12 @@ interface BlockAttributes {
interface Attributes {
textAlign: 'left' | 'center' | 'right';
- isDescendentOfSingleProduct: boolean;
- isDescendentOfSingleProductBlock: boolean;
productId: number;
}
interface Context {
queryId: number;
+ postId: number;
}
interface Props {
@@ -62,19 +60,6 @@ const PriceEdit = ( {
isDescendentOfSingleProductTemplate = false;
}
- useEffect(
- () =>
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductTemplate,
- } ),
- [
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductTemplate,
- setAttributes,
- ]
- );
-
const isExperimentalWcRestApiEnabled = isExperimentalWcRestApiV4Enabled();
const { product } = useProduct( context.postId );
@@ -96,6 +81,9 @@ const PriceEdit = ( {
isExperimentalWcRestApiEnabled ? (
<Block
{ ...blockAttrs }
+ isDescendentOfSingleProductTemplate={
+ isDescendentOfSingleProductTemplate
+ }
isAdmin={ true }
product={ product }
isExperimentalWcRestApiV4Enabled={
@@ -105,6 +93,9 @@ const PriceEdit = ( {
) : (
<Block
{ ...blockAttrs }
+ isDescendentOfSingleProductTemplate={
+ isDescendentOfSingleProductTemplate
+ }
product={ undefined }
isAdmin={ false }
isExperimentalWcRestApiV4Enabled={ false }
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/index.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/index.tsx
index f88f6806a93..f8377843f6d 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/index.tsx
@@ -7,9 +7,9 @@ import { currencyDollar, Icon } from '@wordpress/icons';
/**
* Internal dependencies
*/
-import save from '../save';
import edit from './edit';
import metadata from './block.json';
+import deprecated from './deprecated';
const blockConfig = {
...metadata,
@@ -20,7 +20,8 @@ const blockConfig = {
/>
),
edit,
- save,
+ save: () => null,
+ deprecated,
};
registerProductBlockType( blockConfig, {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/types.ts
index bfbdb99815a..24645514a82 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/price/types.ts
@@ -2,6 +2,4 @@ export interface BlockAttributes {
productId?: number;
className?: string;
textAlign?: 'left' | 'center' | 'right';
- isDescendentOfQueryLoop?: boolean;
- isDescendentOfSingleProductTemplate?: boolean;
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.json
index c07741dcc67..66032da4397 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.json
@@ -8,21 +8,9 @@
"type": "number",
"default": 0
},
- "isDescendentOfQueryLoop": {
- "type": "boolean",
- "default": false
- },
"textAlign": {
"type": "string",
"default": ""
- },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductTemplate": {
- "type": "boolean",
- "default": false
}
},
"supports": {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.tsx
index 7e63e358f83..82971214e8e 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/block.tsx
@@ -48,8 +48,6 @@ const ReviewsCount = ( props: { reviews: number } ): JSX.Element => {
type ProductRatingCounterProps = {
className?: string;
textAlign?: string;
- isDescendentOfSingleProductBlock: boolean;
- isDescendentOfQueryLoop: boolean;
postId: number;
productId: number;
shouldDisplayMockedReviewsWhenProductHasNoReviews: boolean;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/edit.tsx
index 723bd77f768..ab09d4854ad 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/edit.tsx
@@ -7,7 +7,6 @@ import {
useBlockProps,
} from '@wordpress/block-editor';
import type { BlockEditProps } from '@wordpress/blocks';
-import { useEffect } from '@wordpress/element';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
/**
@@ -15,8 +14,6 @@ import { ProductQueryContext as Context } from '@woocommerce/blocks/product-quer
*/
import Block from './block';
import { BlockAttributes } from './types';
-import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';
-import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
const Edit = (
props: BlockEditProps< BlockAttributes > & { context: Context }
@@ -30,30 +27,6 @@ const Edit = (
...context,
shouldDisplayMockedReviewsWhenProductHasNoReviews: true,
};
- const isDescendentOfQueryLoop = Number.isFinite( context.queryId );
- const { isDescendentOfSingleProductBlock } =
- useIsDescendentOfSingleProductBlock( {
- blockClientId: blockProps?.id,
- } );
- let { isDescendentOfSingleProductTemplate } =
- useIsDescendentOfSingleProductTemplate();
-
- if ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {
- isDescendentOfSingleProductTemplate = false;
- }
-
- useEffect( () => {
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- isDescendentOfSingleProductTemplate,
- } );
- }, [
- setAttributes,
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- isDescendentOfSingleProductTemplate,
- ] );
return (
<>
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/types.ts
index f6f8e5296ac..b6866c74db4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-counter/types.ts
@@ -1,7 +1,4 @@
export interface BlockAttributes {
productId: number;
- isDescendentOfQueryLoop: boolean;
- isDescendentOfSingleProductBlock: boolean;
- isDescendentOfSingleProductTemplate: boolean;
textAlign: string;
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.json
index 48f10979b69..444e3bee147 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.json
@@ -8,21 +8,9 @@
"type": "number",
"default": 0
},
- "isDescendentOfQueryLoop": {
- "type": "boolean",
- "default": false
- },
"textAlign": {
"type": "string",
"default": ""
- },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductTemplate": {
- "type": "boolean",
- "default": false
}
},
"usesContext": [ "query", "queryId", "postId" ],
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.tsx
index f6d7f094da6..472d745d088 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/block.tsx
@@ -21,7 +21,6 @@ import './style.scss';
interface ProductRatingStarsProps {
className?: string;
textAlign?: string;
- isDescendentOfQueryLoop: boolean;
postId: number;
productId: number;
shouldDisplayMockedReviewsWhenProductHasNoReviews: boolean;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/edit.tsx
index 7094c80853d..0ca0def8873 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/edit.tsx
@@ -7,7 +7,6 @@ import {
useBlockProps,
} from '@wordpress/block-editor';
import type { BlockEditProps } from '@wordpress/blocks';
-import { useEffect } from '@wordpress/element';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
/**
@@ -15,8 +14,6 @@ import { ProductQueryContext as Context } from '@woocommerce/blocks/product-quer
*/
import Block from './block';
import { BlockAttributes } from './types';
-import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';
-import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
const Edit = (
props: BlockEditProps< BlockAttributes > & { context: Context }
@@ -30,30 +27,6 @@ const Edit = (
...context,
shouldDisplayMockedReviewsWhenProductHasNoReviews: true,
};
- const isDescendentOfQueryLoop = Number.isFinite( context.queryId );
- const { isDescendentOfSingleProductBlock } =
- useIsDescendentOfSingleProductBlock( {
- blockClientId: blockProps?.id,
- } );
- let { isDescendentOfSingleProductTemplate } =
- useIsDescendentOfSingleProductTemplate();
-
- if ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {
- isDescendentOfSingleProductTemplate = false;
- }
-
- useEffect( () => {
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- isDescendentOfSingleProductTemplate,
- } );
- }, [
- setAttributes,
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- isDescendentOfSingleProductTemplate,
- ] );
return (
<>
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/types.ts
index f6f8e5296ac..b6866c74db4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating-stars/types.ts
@@ -1,7 +1,4 @@
export interface BlockAttributes {
productId: number;
- isDescendentOfQueryLoop: boolean;
- isDescendentOfSingleProductBlock: boolean;
- isDescendentOfSingleProductTemplate: boolean;
textAlign: string;
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.json
index 7d86c79c9c3..255560aec58 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.json
@@ -9,21 +9,9 @@
"type": "number",
"default": 0
},
- "isDescendentOfQueryLoop": {
- "type": "boolean",
- "default": false
- },
"textAlign": {
"type": "string",
"default": ""
- },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductTemplate": {
- "type": "boolean",
- "default": false
}
},
"supports": {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/deprecated.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/deprecated.ts
new file mode 100644
index 00000000000..8991bc11921
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/deprecated.ts
@@ -0,0 +1,28 @@
+/**
+ * Internal dependencies
+ */
+import metadata from './block.json';
+import save from '../save';
+
+const { attributes: blockAttributes } = metadata;
+
+const v1 = {
+ attributes: {
+ ...blockAttributes,
+ isDescendentOfQueryLoop: { type: 'boolean', default: false },
+ isDescendentOfSingleProductTemplate: {
+ type: 'boolean',
+ default: false,
+ },
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
+ },
+ save,
+ apiVersion: 3,
+};
+
+const deprecated = [ v1 ];
+
+export default deprecated;
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
index f6090020b46..6c170f24339 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
@@ -7,7 +7,6 @@ import {
useBlockProps,
} from '@wordpress/block-editor';
import type { BlockEditProps } from '@wordpress/blocks';
-import { useEffect } from '@wordpress/element';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
import { useProduct } from '@woocommerce/entities';
@@ -17,8 +16,6 @@ import { useProduct } from '@woocommerce/entities';
import Block from './block';
import { BlockAttributes } from './types';
import './editor.scss';
-import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';
-import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
const Edit = (
props: BlockEditProps< BlockAttributes > & { context: Context }
@@ -33,29 +30,6 @@ const Edit = (
shouldDisplayMockedReviewsWhenProductHasNoReviews: true,
};
const isDescendentOfQueryLoop = Number.isFinite( context.queryId );
- const { isDescendentOfSingleProductBlock } =
- useIsDescendentOfSingleProductBlock( {
- blockClientId: blockProps?.id,
- } );
- let { isDescendentOfSingleProductTemplate } =
- useIsDescendentOfSingleProductTemplate();
-
- if ( isDescendentOfQueryLoop || isDescendentOfSingleProductBlock ) {
- isDescendentOfSingleProductTemplate = false;
- }
-
- useEffect( () => {
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- isDescendentOfSingleProductTemplate,
- } );
- }, [
- setAttributes,
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductBlock,
- isDescendentOfSingleProductTemplate,
- ] );
const { product } = useProduct( context.postId );
@@ -70,7 +44,12 @@ const Edit = (
/>
</BlockControls>
<div { ...blockProps }>
- <Block isAdmin={ true } { ...blockAttrs } product={ product } />
+ <Block
+ isAdmin={ true }
+ { ...blockAttrs }
+ isDescendentOfQueryLoop={ isDescendentOfQueryLoop }
+ product={ product }
+ />
</div>
</>
);
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/index.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/index.ts
index 9d84da2896f..d9b0faa38e4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/index.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/index.ts
@@ -7,16 +7,18 @@ import { registerProductBlockType } from '@woocommerce/atomic-utils';
/**
* Internal dependencies
*/
-import save from '../save';
+
import edit from './edit';
import { BLOCK_ICON as icon } from './constants';
import metadata from './block.json';
+import deprecated from './deprecated';
const blockConfig: BlockConfiguration = {
...metadata,
icon: { src: icon },
edit,
- save,
+ save: () => null,
+ deprecated,
};
registerProductBlockType( blockConfig, {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/types.ts
index f6f8e5296ac..b6866c74db4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/types.ts
@@ -1,7 +1,4 @@
export interface BlockAttributes {
productId: number;
- isDescendentOfQueryLoop: boolean;
- isDescendentOfSingleProductBlock: boolean;
- isDescendentOfSingleProductTemplate: boolean;
textAlign: string;
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/block.json
index d520e1e4f02..dd5951359ee 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/block.json
@@ -4,16 +4,7 @@
"description": "Displays an on-sale badge if the product is on-sale.",
"category": "woocommerce-product-elements",
"attributes": {
- "productId": { "type": "number", "default": 0 },
- "isDescendentOfQueryLoop": { "type": "boolean", "default": false },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductTemplate": {
- "type": "boolean",
- "default": false
- }
+ "productId": { "type": "number", "default": 0 }
},
"supports": {
"interactivity": {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/deprecated.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/deprecated.ts
index c6fdb5d6a8b..724fd5b4f89 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/deprecated.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/deprecated.ts
@@ -19,6 +19,10 @@ const v1 = {
type: 'boolean',
default: false,
},
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
},
save,
apiVersion: 3,
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/types.ts
index 372c788d610..e64df6f3d4f 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/sale-badge/types.ts
@@ -1,6 +1,3 @@
export interface BlockAttributes {
productId: number;
- isDescendentOfQueryLoop?: boolean | undefined;
- isDescendentOfSingleProductTemplate?: boolean;
- isDescendentOfSingleProductBlock?: boolean;
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/block.json b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/block.json
index 5b9a049e017..7e4f9ba3d78 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/block.json
@@ -9,18 +9,6 @@
"type": "number",
"default": 0
},
- "isDescendentOfQueryLoop": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductTemplate": {
- "type": "boolean",
- "default": false
- },
- "isDescendentOfSingleProductBlock": {
- "type": "boolean",
- "default": false
- },
"isDescendantOfAllProducts": {
"type": "boolean",
"default": false
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/edit.tsx
index d20d30cf349..576b7415fb0 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/edit.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/edit.tsx
@@ -2,7 +2,6 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
-import { useEffect } from '@wordpress/element';
import {
useBlockProps,
InspectorControls,
@@ -17,13 +16,12 @@ import {
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
+import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
/**
* Internal dependencies
*/
import Block from './block';
-import { useIsDescendentOfSingleProductBlock } from '../shared/use-is-descendent-of-single-product-block';
-import { useIsDescendentOfSingleProductTemplate } from '../shared/use-is-descendent-of-single-product-template';
import type { EditProps, ControlProps } from './types';
import './editor.scss';
@@ -160,8 +158,6 @@ const Edit = ( {
} = attributes;
const isDescendentOfQueryLoop = Number.isFinite( context.queryId );
- const { isDescendentOfSingleProductBlock } =
- useIsDescendentOfSingleProductBlock( { blockClientId: blockProps.id } );
let { isDescendentOfSingleProductTemplate } =
useIsDescendentOfSingleProductTemplate();
@@ -170,26 +166,18 @@ const Edit = ( {
isDescendentOfSingleProductTemplate = false;
}
- useEffect(
- () =>
- setAttributes( {
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductTemplate,
- isDescendentOfSingleProductBlock,
- } ),
- [
- setAttributes,
- isDescendentOfQueryLoop,
- isDescendentOfSingleProductTemplate,
- isDescendentOfSingleProductBlock,
- ]
- );
-
const { product } = useProduct( context.postId );
return (
<div { ...blockProps }>
- <Block isAdmin={ true } { ...attributes } product={ product } />
+ <Block
+ isAdmin={ true }
+ { ...attributes }
+ isDescendentOfSingleProductTemplate={
+ isDescendentOfSingleProductTemplate
+ }
+ product={ product }
+ />
<InspectorControls>
<ToolsPanel
label={ __( 'Settings', 'woocommerce' ) }
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/index.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/index.ts
index 5795efd6562..e93eb8aff5c 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/index.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/index.ts
@@ -15,6 +15,22 @@ import metadata from './block.json';
import './upgrade';
const deprecated = [
+ {
+ attributes: {
+ ...metadata.attributes,
+ isDescendentOfQueryLoop: { type: 'boolean', default: false },
+ isDescendentOfSingleProductTemplate: {
+ type: 'boolean',
+ default: false,
+ },
+ isDescendentOfSingleProductBlock: {
+ type: 'boolean',
+ default: false,
+ },
+ },
+ save,
+ apiVersion: 3,
+ },
{
save,
migrate: ( attributes: BlockAttributes ) => {
@@ -38,7 +54,7 @@ const blockConfig = {
icon: { src: icon },
deprecated,
edit,
- save,
+ save: () => null,
};
registerProductBlockType( blockConfig, {
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/types.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/types.ts
index c72d43f189a..f8c00249238 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/types.ts
@@ -8,9 +8,7 @@ import type { ProductEntityResponse } from '@woocommerce/entities';
export interface Attributes {
productId: number;
- isDescendentOfQueryLoop: boolean;
- isDescendentOfSingleProductTemplate: boolean;
- isDescendentOfSingleProductBlock: boolean;
+
isDescendantOfAllProducts: boolean;
showDescriptionIfEmpty: boolean;
showLink: boolean;
@@ -34,4 +32,5 @@ export type BlockProps = Attributes & {
className?: string;
product?: ProductEntityResponse | null | undefined;
isAdmin?: boolean;
+ isDescendentOfSingleProductTemplate?: boolean;
};
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/constants.ts b/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/constants.ts
index d37e47ddf52..d3c4e7f743c 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/constants.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/grouped-product-selector/product-item/constants.ts
@@ -70,7 +70,6 @@ export const GROUPED_PRODUCT_ITEM_TEMPLATE: TemplateArray = [
[
'woocommerce/product-price',
{
- isDescendentOfSingleProductBlock: true,
fontSize: 'medium',
textAlign: 'right',
style: {
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/cart/cart-cross-sells-product-list/cart-cross-sells-product.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/cart/cart-cross-sells-product-list/cart-cross-sells-product.tsx
index 4e66a932fcb..8adde07e84c 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/cart/cart-cross-sells-product-list/cart-cross-sells-product.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/cart/cart-cross-sells-product-list/cart-cross-sells-product.tsx
@@ -43,7 +43,6 @@ const CartCrossSellsProduct = ( {
showProductLink={ true }
saleBadgeAlign={ 'left' }
imageSizing={ ImageSizing.SINGLE }
- isDescendentOfQueryLoop={ false }
scale={ 'cover' }
aspectRatio={ '1:1' }
/>
@@ -53,8 +52,6 @@ const CartCrossSellsProduct = ( {
showProductLink={ true }
/>
<ProductRating
- isDescendentOfQueryLoop={ false }
- isDescendentOfSingleProductBlock={ false }
productId={ product.id }
postId={ 0 }
shouldDisplayMockedReviewsWhenProductHasNoReviews={
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/single-product.ts b/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/single-product.ts
index 757f97969c0..f2f09a4e222 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/single-product.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/single-product.ts
@@ -48,9 +48,7 @@ const getBlockifiedTemplate = () =>
createBlock( 'woocommerce/product-price', {
fontSize: 'large',
} ),
- createBlock( 'woocommerce/product-summary', {
- isDescendentOfSingleProductTemplate: true,
- } ),
+ createBlock( 'woocommerce/product-summary' ),
createBlock(
getSetting( 'isBlockTheme', false )
? 'woocommerce/add-to-cart-with-options'
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/single-product/constants.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/single-product/constants.tsx
index a1498b2153f..d3d94ff3039 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/single-product/constants.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/single-product/constants.tsx
@@ -38,18 +38,9 @@ export const DEFAULT_INNER_BLOCKS: InnerBlockTemplate[] = [
PRODUCT_TITLE_VARIATION_NAME,
},
],
- [
- 'woocommerce/product-rating',
- { isDescendentOfSingleProductBlock: true },
- ],
- [
- 'woocommerce/product-price',
- { isDescendentOfSingleProductBlock: true },
- ],
- [
- 'woocommerce/product-summary',
- { isDescendentOfSingleProductBlock: true },
- ],
+ [ 'woocommerce/product-rating' ],
+ [ 'woocommerce/product-price' ],
+ [ 'woocommerce/product-summary' ],
[
getSetting( 'isBlockTheme', false )
? 'woocommerce/add-to-cart-with-options'
diff --git a/plugins/woocommerce/client/blocks/changelog/fix-product-block-ancestry-review b/plugins/woocommerce/client/blocks/changelog/fix-product-block-ancestry-review
new file mode 100644
index 00000000000..33921663f5c
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/changelog/fix-product-block-ancestry-review
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Preserve product rating review links and remove obsolete attributes from product block templates.
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index cadf615510b..b113382eddc 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -3170,15 +3170,15 @@ EOT;
<div class="wp-block-woocommerce-product-collection"><!-- wp:pattern {"slug":"woocommerce/cart-cross-sells-message"} /-->
<!-- wp:woocommerce/product-template -->
-<!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
+<!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
<!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}},"typography":{"lineHeight":"1.4"}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
-<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+<!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
-<!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+<!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template --></div>
<!-- /wp:woocommerce/product-collection --></div>
diff --git a/plugins/woocommerce/patterns/related-products.php b/plugins/woocommerce/patterns/related-products.php
index 3a06b3ae7ed..5bdef6a1178 100644
--- a/plugins/woocommerce/patterns/related-products.php
+++ b/plugins/woocommerce/patterns/related-products.php
@@ -21,12 +21,12 @@
<!-- /wp:heading -->
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 66e9c7fbd68..7879bfce6d2 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -51784,12 +51784,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/ProductQuery.php
- -
- message: '#^Access to property \$context on an unknown class Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
- identifier: class.notFound
- count: 2
- path: src/Blocks/BlockTypes/ProductRating.php
-
-
message: '#^Method Automattic\\WooCommerce\\Blocks\\BlockTypes\\ProductRating\:\:get_block_type_style\(\) should return null but returns array\<mixed, mixed\>\.$#'
identifier: return.type
@@ -51820,18 +51814,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/ProductRating.php
- -
- message: '#^Parameter \$block of method Automattic\\WooCommerce\\Blocks\\BlockTypes\\ProductRating\:\:render\(\) has invalid type Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
- identifier: class.notFound
- count: 1
- path: src/Blocks/BlockTypes/ProductRating.php
-
- -
- message: '#^Access to property \$context on an unknown class Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
- identifier: class.notFound
- count: 1
- path: src/Blocks/BlockTypes/ProductRatingCounter.php
-
-
message: '#^Method Automattic\\WooCommerce\\Blocks\\BlockTypes\\ProductRatingCounter\:\:get_block_type_uses_context\(\) has no return type specified\.$#'
identifier: missingType.return
@@ -51850,12 +51832,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/ProductRatingCounter.php
- -
- message: '#^Parameter \$block of method Automattic\\WooCommerce\\Blocks\\BlockTypes\\ProductRatingCounter\:\:render\(\) has invalid type Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
- identifier: class.notFound
- count: 1
- path: src/Blocks/BlockTypes/ProductRatingCounter.php
-
-
message: '#^Access to property \$context on an unknown class Automattic\\WooCommerce\\Blocks\\BlockTypes\\WP_Block\.$#'
identifier: class.notFound
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImage.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImage.php
index 422edfd6029..ed24b14043f 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImage.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImage.php
@@ -46,12 +46,10 @@ class ProductImage extends AbstractBlock {
private function parse_attributes( $attributes ) {
// These should match what's set in JS `registerBlockType`.
$defaults = array(
- 'showProductLink' => true,
- 'imageSizing' => 'single',
- 'productId' => 'number',
- 'isDescendentOfQueryLoop' => 'false',
- 'isDescendentOfSingleProductBlock' => 'false',
- 'scale' => 'cover',
+ 'showProductLink' => true,
+ 'imageSizing' => 'single',
+ 'productId' => 'number',
+ 'scale' => 'cover',
);
return wp_parse_args( $attributes, $defaults );
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php
index 223dec10124..0df1a87e945 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRating.php
@@ -21,25 +21,6 @@ class ProductRating extends AbstractBlock {
*/
protected $api_version = '3';
- /**
- * Get the block's attributes.
- *
- * @param array $attributes Block attributes. Default empty array.
- * @return array Block attributes merged with defaults.
- */
- private function parse_attributes( $attributes ) {
- // These should match what's set in JS `registerBlockType`.
- $defaults = array(
- 'productId' => 0,
- 'isDescendentOfQueryLoop' => false,
- 'textAlign' => '',
- 'isDescendentOfSingleProductBlock' => false,
- 'isDescendentOfSingleProductTemplate' => false,
- );
-
- return wp_parse_args( $attributes, $defaults );
- }
-
/**
* Overwrite parent method to prevent script registration.
*
@@ -69,9 +50,9 @@ class ProductRating extends AbstractBlock {
/**
* Include and render the block.
*
- * @param array $attributes Block attributes. Default empty array.
- * @param string $content Block content. Default empty string.
- * @param WP_Block $block Block instance.
+ * @param array $attributes Block attributes. Default empty array.
+ * @param string $content Block content. Default empty string.
+ * @param \WP_Block $block Block instance.
* @return string Rendered block type output.
*/
protected function render( $attributes, $content, $block ) {
@@ -89,9 +70,9 @@ class ProductRating extends AbstractBlock {
&& wc_reviews_enabled() ) {
$product_reviews_count = $product->get_review_count();
$product_rating = $product->get_average_rating();
- $parsed_attributes = $this->parse_attributes( $attributes );
- $is_descendent_of_single_product_block = $parsed_attributes['isDescendentOfSingleProductBlock'];
- $is_descendent_of_single_product_template = $parsed_attributes['isDescendentOfSingleProductTemplate'];
+ $global_product = $GLOBALS['product'] ?? null;
+ $is_descendent_of_single_product_block = ! isset( $block->context['queryId'] ) && ( ! $global_product instanceof \WC_Product || (int) $post_id !== $global_product->get_id() );
+ $is_descendent_of_single_product_template = ! isset( $block->context['queryId'] ) && ! $is_descendent_of_single_product_block;
$styles_and_classes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
$text_align_styles_and_classes = StyleAttributesUtils::get_text_align_class_and_style( $attributes );
@@ -104,7 +85,7 @@ class ProductRating extends AbstractBlock {
* @param int $count Total number of ratings.
* @return string
*/
- $filter_rating_html = function( $html, $rating, $count ) use ( $post_id, $product_rating, $product_reviews_count, $is_descendent_of_single_product_block, $is_descendent_of_single_product_template ) {
+ $filter_rating_html = function ( $html, $rating, $count ) use ( $post_id, $product_rating, $product_reviews_count, $is_descendent_of_single_product_block, $is_descendent_of_single_product_template ) {
$product_permalink = get_permalink( $post_id );
$reviews_count = $count;
$average_rating = $rating;
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRatingCounter.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRatingCounter.php
index 037be048310..051a876c0e6 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductRatingCounter.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductRatingCounter.php
@@ -21,25 +21,6 @@ class ProductRatingCounter extends AbstractBlock {
*/
protected $api_version = '3';
- /**
- * Get the block's attributes.
- *
- * @param array $attributes Block attributes. Default empty array.
- * @return array Block attributes merged with defaults.
- */
- private function parse_attributes( $attributes ) {
- // These should match what's set in JS `registerBlockType`.
- $defaults = array(
- 'productId' => 0,
- 'isDescendentOfQueryLoop' => false,
- 'textAlign' => '',
- 'isDescendentOfSingleProductBlock' => false,
- 'isDescendentOfSingleProductTemplate' => false,
- );
-
- return wp_parse_args( $attributes, $defaults );
- }
-
/**
* Overwrite parent method to prevent script registration.
*
@@ -69,9 +50,9 @@ class ProductRatingCounter extends AbstractBlock {
/**
* Include and render the block.
*
- * @param array $attributes Block attributes. Default empty array.
- * @param string $content Block content. Default empty string.
- * @param WP_Block $block Block instance.
+ * @param array $attributes Block attributes. Default empty array.
+ * @param string $content Block content. Default empty string.
+ * @param \WP_Block $block Block instance.
* @return string Rendered block type output.
*/
protected function render( $attributes, $content, $block ) {
@@ -87,9 +68,9 @@ class ProductRatingCounter extends AbstractBlock {
if ( $product && $product->get_review_count() > 0 ) {
$product_reviews_count = $product->get_review_count();
$product_rating = $product->get_average_rating();
- $parsed_attributes = $this->parse_attributes( $attributes );
- $is_descendent_of_single_product_block = $parsed_attributes['isDescendentOfSingleProductBlock'];
- $is_descendent_of_single_product_template = $parsed_attributes['isDescendentOfSingleProductTemplate'];
+ $global_product = $GLOBALS['product'] ?? null;
+ $is_descendent_of_single_product_block = ! isset( $block->context['queryId'] ) && ( ! $global_product instanceof \WC_Product || (int) $post_id !== $global_product->get_id() );
+ $is_descendent_of_single_product_template = ! isset( $block->context['queryId'] ) && ! $is_descendent_of_single_product_block;
$styles_and_classes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
$text_align_styles_and_classes = StyleAttributesUtils::get_text_align_class_and_style( $attributes );
diff --git a/plugins/woocommerce/templates/parts/grouped-product-add-to-cart-with-options.html b/plugins/woocommerce/templates/parts/grouped-product-add-to-cart-with-options.html
index 5e296b3d1e6..400367b86df 100644
--- a/plugins/woocommerce/templates/parts/grouped-product-add-to-cart-with-options.html
+++ b/plugins/woocommerce/templates/parts/grouped-product-add-to-cart-with-options.html
@@ -19,7 +19,7 @@
<!-- wp:group {"style":{"spacing":{"blockGap":"0"}},"layout":{"type":"flex","orientation":"vertical","justifyContent":"right"}} -->
<div class="wp-block-group">
- <!-- wp:woocommerce/product-price {"textAlign":"right","isDescendentOfSingleProductTemplate":true,"isDescendentOfSingleProductBlock":true,"style":{"typography":{"fontWeight":400,"fontStyle":"normal"}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"right","style":{"typography":{"fontWeight":400,"fontStyle":"normal"}}} /-->
<!-- wp:woocommerce/product-stock-indicator {"fontSize":"small"} /--></div>
<!-- /wp:group -->
</div>
diff --git a/plugins/woocommerce/templates/templates/blockified/archive-product.html b/plugins/woocommerce/templates/templates/blockified/archive-product.html
index 8f822a80073..7f3d07e19d8 100644
--- a/plugins/woocommerce/templates/templates/blockified/archive-product.html
+++ b/plugins/woocommerce/templates/templates/blockified/archive-product.html
@@ -19,12 +19,12 @@
<!-- wp:woocommerce/product-collection {"queryId":0,"query":{"woocommerceAttributes":[],"woocommerceStockStatus":["instock","outofstock","onbackorder"],"taxQuery":{},"isProductCollectionBlock":true,"perPage":10,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":true},"tagName":"div","dimensions":{"widthType":"fill","fixedWidth":""},"displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"convertedFromProducts":false,"queryContextIncludes":["collection"],"align":"wide"} -->
<div class="wp-block-woocommerce-product-collection alignwide">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":2,"isLink":true,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title","style":{"typography":{"lineHeight":"1.4"}}} /-->
- <!-- wp:woocommerce/product-price {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:woocommerce/product-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
diff --git a/plugins/woocommerce/templates/templates/blockified/product-search-results.html b/plugins/woocommerce/templates/templates/blockified/product-search-results.html
index 67795853cac..d77d935d5e3 100644
--- a/plugins/woocommerce/templates/templates/blockified/product-search-results.html
+++ b/plugins/woocommerce/templates/templates/blockified/product-search-results.html
@@ -17,12 +17,12 @@
<!-- wp:woocommerce/product-collection {"queryId":0,"query":{"woocommerceAttributes":[],"woocommerceStockStatus":["instock","outofstock","onbackorder"],"taxQuery":{},"isProductCollectionBlock":true,"perPage":10,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":true},"tagName":"div","dimensions":{"widthType":"fill","fixedWidth":""},"displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"convertedFromProducts":false,"queryContextIncludes":["collection"],"align":"wide"} -->
<div class="wp-block-woocommerce-product-collection alignwide">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":2,"isLink":true,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title","style":{"typography":{"lineHeight":"1.4"}}} /-->
- <!-- wp:woocommerce/product-price {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:woocommerce/product-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
diff --git a/plugins/woocommerce/templates/templates/blockified/single-product.html b/plugins/woocommerce/templates/templates/blockified/single-product.html
index dca94269c71..d448e93ca26 100644
--- a/plugins/woocommerce/templates/templates/blockified/single-product.html
+++ b/plugins/woocommerce/templates/templates/blockified/single-product.html
@@ -17,9 +17,9 @@
<div class="wp-block-column">
<!-- wp:post-title {"level": 1, "__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-rating {"isDescendentOfSingleProductTemplate":true} /-->
+ <!-- wp:woocommerce/product-rating /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfSingleProductTemplate":true, "fontSize":"large"} /-->
+ <!-- wp:woocommerce/product-price {"fontSize":"large"} /-->
<!-- wp:post-excerpt {"__woocommerceNamespace":"woocommerce/product-query/product-summary", "excerptLength":100} /-->
diff --git a/plugins/woocommerce/templates/templates/blockified/taxonomy-product_attribute.html b/plugins/woocommerce/templates/templates/blockified/taxonomy-product_attribute.html
index d51ecbe08a4..d7907acdc4e 100644
--- a/plugins/woocommerce/templates/templates/blockified/taxonomy-product_attribute.html
+++ b/plugins/woocommerce/templates/templates/blockified/taxonomy-product_attribute.html
@@ -21,12 +21,12 @@
<!-- wp:woocommerce/product-collection {"queryId":0,"query":{"woocommerceAttributes":[],"woocommerceStockStatus":["instock","outofstock","onbackorder"],"taxQuery":{},"isProductCollectionBlock":true,"perPage":10,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":true},"tagName":"div","dimensions":{"widthType":"fill","fixedWidth":""},"displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"convertedFromProducts":false,"queryContextIncludes":["collection"],"align":"wide"} -->
<div class="wp-block-woocommerce-product-collection alignwide">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":2,"isLink":true,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title","style":{"typography":{"lineHeight":"1.4"}}} /-->
- <!-- wp:woocommerce/product-price {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:woocommerce/product-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
diff --git a/plugins/woocommerce/tests/e2e/bin/blocks/pages/cart.html b/plugins/woocommerce/tests/e2e/bin/blocks/pages/cart.html
index 16a4c2bc30b..8c1c39b0565 100644
--- a/plugins/woocommerce/tests/e2e/bin/blocks/pages/cart.html
+++ b/plugins/woocommerce/tests/e2e/bin/blocks/pages/cart.html
@@ -12,12 +12,12 @@
<div class="wp-block-woocommerce-product-collection">
<!-- wp:pattern {"slug":"woocommerce/cart-cross-sells-message"} /-->
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
<!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}},"typography":{"lineHeight":"1.4"}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/bin/blocks/posts/product-collection.html b/plugins/woocommerce/tests/e2e/bin/blocks/posts/product-collection.html
index 92b641d7d02..e0748cbf62a 100644
--- a/plugins/woocommerce/tests/e2e/bin/blocks/posts/product-collection.html
+++ b/plugins/woocommerce/tests/e2e/bin/blocks/posts/product-collection.html
@@ -1,13 +1,13 @@
<!-- wp:woocommerce/product-collection {"queryId":0,"query":{"perPage":16,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":false,"taxQuery":{},"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true}} -->
<div class="wp-block-woocommerce-product-collection"><!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars
index d6d84f4f91d..651a0eda658 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars
@@ -19,14 +19,14 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class='wp-block-woocommerce-product-collection'>
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_attribute-filter.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_attribute-filter.handlebars
index 3f267906472..2c1a1771386 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_attribute-filter.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_attribute-filter.handlebars
@@ -29,14 +29,14 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class="wp-block-woocommerce-product-collection">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars
index 561e0061c58..e67bed2ac34 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars
@@ -66,14 +66,14 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class="wp-block-woocommerce-product-collection">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_multiple-product-filters.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_multiple-product-filters.handlebars
index 08e378ebf53..fb7a67bf479 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_multiple-product-filters.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_multiple-product-filters.handlebars
@@ -29,14 +29,14 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class="wp-block-woocommerce-product-collection">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars
index 11d8fc9eddd..6fec612dc86 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars
@@ -9,14 +9,14 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class='wp-block-woocommerce-product-collection'>
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars
index 8fb3c015acb..f83b269c82b 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars
@@ -9,14 +9,14 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class="wp-block-woocommerce-product-collection">
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars
index 21bd9c92d3d..b91a9d97b91 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars
@@ -9,15 +9,15 @@
<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
<div class='wp-block-woocommerce-product-collection'>
<!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} -->
- <!-- wp:woocommerce/product-sale-badge {"isDescendentOfQueryLoop":true,"align":"right"} /-->
+ <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
+ <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
<!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
- <!-- wp:woocommerce/product-button {"textAlign":"center","isDescendentOfQueryLoop":true,"fontSize":"small"} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductRatingTest.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductRatingTest.php
index fc8cef6b6b1..1f25dc4576a 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductRatingTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductRatingTest.php
@@ -54,7 +54,7 @@ class ProductRatingTest extends WC_Unit_Test_Case {
$markup = do_blocks(
'<!-- wp:woocommerce/single-product {"productId":' . $product->get_id() . '} -->' .
- '<!-- wp:woocommerce/product-rating {"isDescendentOfSingleProductBlock":true} /-->' .
+ '<!-- wp:woocommerce/product-rating /-->' .
'<!-- /wp:woocommerce/single-product -->'
);
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/SingleProduct.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/SingleProduct.php
index 5d3a0d2be2a..18ed382ee68 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/SingleProduct.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/SingleProduct.php
@@ -92,7 +92,7 @@ class SingleProduct extends \WP_UnitTestCase {
<!-- wp:woocommerce/product-gallery-large-image -->
<div class="wp-block-woocommerce-product-gallery-large-image wc-block-product-gallery-large-image__inner-blocks">
-<!-- wp:woocommerce/product-image {"showProductLink":false,"showSaleBadge":false,"isDescendentOfSingleProductBlock":true} /-->
+<!-- wp:woocommerce/product-image {"showProductLink":false,"showSaleBadge":false} /-->
<!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
@@ -107,11 +107,11 @@ class SingleProduct extends \WP_UnitTestCase {
<div class="wp-block-column">
<!-- wp:post-title {"isLink":true,"__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
-<!-- wp:woocommerce/product-rating {"isDescendentOfSingleProductBlock":true} /-->
+<!-- wp:woocommerce/product-rating /-->
-<!-- wp:woocommerce/product-price {"isDescendentOfSingleProductBlock":true} /-->
+<!-- wp:woocommerce/product-price /-->
-<!-- wp:woocommerce/product-summary {"isDescendentOfSingleProductBlock":true} /-->
+<!-- wp:woocommerce/product-summary /-->
<!-- wp:woocommerce/product-meta -->
<div class="wp-block-woocommerce-product-meta"></div>
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateCompatibilityTests.php b/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateCompatibilityTests.php
index 66d39d88aa5..e2b2b1ef248 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateCompatibilityTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateCompatibilityTests.php
@@ -96,10 +96,10 @@ class SingleProductTemplateCompatibilityTests extends WP_UnitTestCase {
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
- <!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
+ <!-- wp:woocommerce/product-image /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
@@ -131,10 +131,10 @@ class SingleProductTemplateCompatibilityTests extends WP_UnitTestCase {
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
- <!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
+ <!-- wp:woocommerce/product-image /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
@@ -243,10 +243,10 @@ class SingleProductTemplateCompatibilityTests extends WP_UnitTestCase {
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
- <!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
+ <!-- wp:woocommerce/product-image /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
@@ -270,10 +270,10 @@ class SingleProductTemplateCompatibilityTests extends WP_UnitTestCase {
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
- <!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
+ <!-- wp:woocommerce/product-image /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php b/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php
index c671e9df61e..dd57bdb535b 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php
@@ -361,9 +361,9 @@ class SingleProductTemplateTests extends WP_UnitTestCase {
<div class="wp-block-column">
<!-- wp:post-title {"level": 1, "__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-rating {"isDescendentOfSingleProductTemplate":true} /-->
+ <!-- wp:woocommerce/product-rating /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfSingleProductTemplate":true, "fontSize":"large"} /-->
+ <!-- wp:woocommerce/product-price {"fontSize":"large"} /-->
<!-- wp:post-excerpt {"__woocommerceNamespace":"woocommerce/product-query/product-summary", "excerptLength":100} /-->
@@ -398,13 +398,13 @@ class SingleProductTemplateTests extends WP_UnitTestCase {
<!-- /wp:heading -->
<!-- wp:post-template {"className":"products-block-post-template","__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
- <!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
+ <!-- wp:woocommerce/product-image /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
- <!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
+ <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->
@@ -456,7 +456,7 @@ class SingleProductTemplateTests extends WP_UnitTestCase {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:woocommerce/product-image-gallery /-->
- <!-- wp:woocommerce/product-price {"isDescendentOfSingleProductTemplate":true} /-->
+ <!-- wp:woocommerce/product-price /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = sprintf(
@@ -528,7 +528,7 @@ class SingleProductTemplateTests extends WP_UnitTestCase {
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column">
- <!-- wp:woocommerce/product-price {"isDescendentOfSingleProductTemplate":true} /-->
+ <!-- wp:woocommerce/product-price /-->
<!-- wp:paragraph -->
<p>Additional information.</p>
<!-- /wp:paragraph -->