This commit is contained in:
Mike Jolley 2023-09-27 12:56:24 +01:00 committed by GitHub
parent 7f7ff60406
commit 241984a265
4 changed files with 23 additions and 13 deletions

View File

@ -3,6 +3,12 @@
*/
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
import { getSetting } from '@woocommerce/settings';
import classnames from 'classnames';
/**
* Internal dependencies
*/
import './editor.scss';
const Edit = ( {
attributes,
@ -18,12 +24,13 @@ const Edit = ( {
'storeHasDownloadableProducts'
);
if ( ! hasDownloadableProducts ) {
return null;
}
return (
<div { ...blockProps }>
<div
{ ...blockProps }
className={ classnames( blockProps.className, {
'store-has-downloads': hasDownloadableProducts,
} ) }
>
<InnerBlocks
allowedBlocks={ [ 'core/heading' ] }
template={ [

View File

@ -0,0 +1,3 @@
.wp-block-woocommerce-order-confirmation-downloads-wrapper:not(.store-has-downloads):not(.is-selected):not(.has-child-selected) {
display: none;
}

View File

@ -2,7 +2,6 @@
* External dependencies
*/
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
import { getSetting } from '@woocommerce/settings';
const Edit = ( {
attributes,
@ -14,13 +13,6 @@ const Edit = ( {
setAttributes: ( attributes: Record< string, unknown > ) => void;
} ) => {
const blockProps = useBlockProps();
const hasDownloadableProducts = getSetting(
'storeHasDownloadableProducts'
);
if ( ! hasDownloadableProducts ) {
return null;
}
return (
<div { ...blockProps }>

View File

@ -51,6 +51,7 @@ final class BlockTypesController {
add_filter( 'render_block', array( $this, 'add_data_attributes' ), 10, 2 );
add_action( 'woocommerce_login_form_end', array( $this, 'redirect_to_field' ) );
add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_legacy_widgets_with_block_equivalent' ) );
add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_product_transients' ) );
}
/**
@ -159,6 +160,13 @@ final class BlockTypesController {
return $widget_types;
}
/**
* Delete product transients when a product is deleted.
*/
public function delete_product_transients() {
delete_transient( 'wc_blocks_has_downloadable_product' );
}
/**
* Get list of block types.
*