From e485e95f4503a10f854115e5bbfeb787c271ee83 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Thu, 17 Aug 2023 15:40:50 +0200 Subject: [PATCH] Enable Auto-insert for the Mini Cart block after the navigation block in the feature plugin. --- src/BlockTypes/MiniCart.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/BlockTypes/MiniCart.php b/src/BlockTypes/MiniCart.php index ea3ac13df9a..fc335714966 100644 --- a/src/BlockTypes/MiniCart.php +++ b/src/BlockTypes/MiniCart.php @@ -72,9 +72,23 @@ public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_ protected function initialize() { parent::initialize(); add_action( 'wp_loaded', array( $this, 'register_empty_cart_message_block_pattern' ) ); + add_action( 'wp_loaded', array( $this, 'register_auto_insert' ) ); add_action( 'wp_print_footer_scripts', array( $this, 'print_lazy_load_scripts' ), 2 ); } + /** + * Auto-insert the Mini cart block after the navigation block. + * + * Since this is still an experimental feature within Gutenberg, this feature is enabled exclusively in the feature plugin. + */ + public function register_auto_insert() { + if ( ! function_exists( 'gutenberg_register_auto_inserted_block' ) || ! WC_BLOCKS_IS_FEATURE_PLUGIN ) { + return; + } + + gutenberg_register_auto_inserted_block( 'woocommerce/mini-cart', 'after', 'core/navigation' ); + } + /** * Get the editor script handle for this block type. *