Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Product SKU: fix product SKU when added in the product meta block (#8966
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gigitux authored Apr 19, 2023
1 parent 7e683d8 commit 3b0242e
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions assets/js/atomic/blocks/product-elements/sku/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { BlockEditProps } from '@wordpress/blocks';
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
import { useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -28,9 +29,34 @@ const Edit = ( {
};
const isDescendentOfQueryLoop = Number.isFinite( context.queryId );

const isDescendentOfSingleProductTemplate = useSelect(
( select ) => {
const store = select( 'core/edit-site' );
const postId = store?.getEditedPostId< string | undefined >();

if ( ! postId ) {
return false;
}

return (
postId.includes( '//single-product' ) &&
! isDescendentOfQueryLoop
);
},
[ isDescendentOfQueryLoop ]
);

useEffect(
() => setAttributes( { isDescendentOfQueryLoop } ),
[ setAttributes, isDescendentOfQueryLoop ]
() =>
setAttributes( {
isDescendentOfQueryLoop,
isDescendentOfSingleProductTemplate,
} ),
[
setAttributes,
isDescendentOfQueryLoop,
isDescendentOfSingleProductTemplate,
]
);

return (
Expand Down

0 comments on commit 3b0242e

Please sign in to comment.