How to Turn off / Disable Unneeded WooCommerce Gutenberg blocks
Spoiler alert – we are going to do that without plugins! 😁🎉
Turning off WooCommerce Gutenberg Blocks in Block Manager
I already talked about in here, actually you do not have to force disable Gutenberg blocks in your code. Anyway, before doing it, please consider turning off blocks in Block Manager which appeared in WordPress 5.2
WooCommerce blocks are also presented there:

Force Disable WooCommerce Gutenberg Blocks in the Code
At the moment of writing this tutorial WooCommerce do not have a filter hook to prevent some of the blocks from being registered, so I am going to show you how to do it with the help of allowed_block_types
filter hook.
There is a whole tutorial about this filter hook on my website.
Anyway, it is not difficult for me to explain one more time how allowed_block_types
works.
- By default this filter hook returns true, which means that all the blocks are allowed by default.
- If you pass into this filter hook an array of block names, like
[ 'core/image', 'core/paragraph' ]
– only these particular blocks will be allowed in Gutenberg. - You can use
WP_Block_Type_Registry::get_instance()->get_all_registered()
to get all the blocks registered by plugins, which can help you. I will show you below, how.
Example 1
The easy one, let’s suppose that’ve inserted this code into your (child) theme functions.php
file:
add_filter( 'allowed_block_types', 'misha_allow_2_woo_blocks' ); function misha_allow_2_woo_blocks( $allowed_blocks ){ $allowed_blocks = array( 'woocommerce/handpicked-products', 'woocommerce/product-on-sale', ); return $allowed_blocks; }
And the result:

That’s too much, right? 😁
Example 2
As you probably understood from our previous example, when you’re using allowed_block_types
, you have two options:
- Either specify all the possible block you would use in your code…
- … or to get the blocks in the code somehow.
WP_Block_Type_Registry::get_instance()->get_all_registered()
will help us with it. This is how:
add_filter( 'allowed_block_types', 'misha_allowed_blocks' ); function misha_allowed_blocks( $allowed_blocks ) { $registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered(); // specify all the blocks you would like to disable here unset( $registered_blocks[ 'woocommerce/all-products' ] ); unset( $registered_blocks[ 'woocommerce/all-reviews' ] ); // etc ... // now $registered_blocks contains only blocks registered by plugins, but we need keys only $registered_blocks = array_keys( $registered_blocks ); // merge the whitelist with plugins blocks $allowed_blocks = array_merge( array( 'core/image', 'core/paragraph', 'core/heading', 'core/list', ), $registered_blocks ); return $allowed_blocks; }
Please let me explain that a little bit:
- Line 3. Variable
$allowed_blocks
is equal1
at the beginning unlessallowed_block_types
is not hooked somewhere else. - Line 5. This method allows us to get the objects as an associative array of all the blocks registered by plugins, and widget blocks by the way. So
$registered_blocks
will contain all the WooCommerce blocks as well. But this method doesn’t return default Gutenberg blocks like paragraph, list etc. - Lines 8-9. As
$registered_blocks
is an associative array, we can easily remove a block element from there if we know its slug. All the WooCommerce block slugs are listed below. - Line 13. We don’t need objects, just block names (slugs).
- Lines 17-22. Unfrotunately we have to pass default block names manually. The full list of default block names (slugs) is here.
List of WooCommerce Gutenberg Block Names / Slugs
woocommerce/all-reviews
– All Reviews,woocommerce/featured-category
– Featured Category,woocommerce/featured-product
– Featured Product,woocommerce/handpicked-products
– Hand-picked Products,woocommerce/product-best-sellers
– Best Selling Productswoocommerce/product-categories
– Product Categories Listwoocommerce/product-category
– Products by Categorywoocommerce/product-new
– Newest Productswoocommerce/product-on-sale
– On Sale Productswoocommerce/products-by-attribute
– Products by Attributewoocommerce/product-top-rated
– Top Rated Productswoocommerce/reviews-by-product
– Reviews by Productwoocommerce/reviews-by-category
– Reviews by Categorywoocommerce/product-search
– Product Searchwoocommerce/product-tag
– Products by Tagwoocommerce/all-products
– All Productswoocommerce/price-filter
– Filter Products by Pricewoocommerce/attribute-filter
– Filter Products by Attributewoocommerce/active-filters
– Active Product Filters
And here is the list of default Gutenberg block names/slugs.
Comments — 1
Nice article
Comments are closed.