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

Mini-Cart: prevent 'Mini-Cart in cart and checkout pages' toggle from showing up in the post/page editor #9442

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions assets/js/blocks/mini-cart/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { getSetting } from '@woocommerce/settings';
import { __ } from '@wordpress/i18n';
import Noninteractive from '@woocommerce/base-components/noninteractive';
import type { ReactElement } from 'react';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -34,14 +33,18 @@ interface Props {
setAttributes: ( attributes: Record< string, unknown > ) => void;
}

const Edit = ( { attributes, setAttributes }: Props ): ReactElement => {
const Edit = ( {
attributes,
setAttributes,
context: { postType, postId },
}: Props ): ReactElement => {
const { addToCartBehaviour, hasHiddenPrice, cartAndCheckoutRenderStyle } =
attributes;
const blockProps = useBlockProps( {
className: `wc-block-mini-cart`,
} );

const isSiteEditor = useSelect( 'core/edit-site' ) !== undefined;
const isSiteEditor = postType === undefined || postId === undefined;

const templatePartEditUri = getSetting(
'templatePartEditUri',
Expand Down
1 change: 1 addition & 0 deletions assets/js/blocks/mini-cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const settings: BlockConfiguration = {
className: 'wc-block-mini-cart--preview',
},
},
usesContext: [ 'postId', 'postType' ],
attributes: {
isPreview: {
type: 'boolean',
Expand Down