如何禁用不必要的WooCommerce的古腾堡区块

Woocommer实在是太强大了,但强大的背后是很多功能也许我们用不上。但它又会出现在我们的使用中,作为强迫症使用者肯定觉得这无法接受。誓要禁用它方可放心,比如Woocommer的古腾堡区块就是其中一个例子。因为woocommer预设了大量古腾堡区块,而这些区块大多数是我们不用或是用不上的。好在Woocommer为我们提供了hook钩子,我们可用通过代码轻松禁用它们。

您只需要将下面的代码稍作修改后放在您的主题functions.php文件里即可

add_filter( 'allowed_block_types', 'ietheme_allowed_blocks' ); 
function ietheme( $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;
}

下面是woocommer的古腾堡区块别名。您可用参考修改上面的代码

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 Products
woocommerce/product-categories //Product Categories List
woocommerce/product-category //Products by Category
woocommerce/product-new //Newest Products
woocommerce/product-on-sale //On Sale Products
woocommerce/products-by-attribute //Products by Attribute
woocommerce/product-top-rated //Top Rated Products
woocommerce/reviews-by-product //Reviews by Product
woocommerce/reviews-by-category //Reviews by Category
woocommerce/product-search //Product Search
woocommerce/product-tag //Products by Tag
woocommerce/all-products //All Products
woocommerce/price-filter //Filter Products by Price
woocommerce/attribute-filter //Filter Products by Attribute
woocommerce/active-filters //Active Product Filters

本文已在Ie主题99839发布

文章来源:https://ietheme.com/remove-woocommerce-blocks.html


撰写评论

您的电子邮箱地址不会被公开。 必填项已用*标注

加入我们

注册完成!

密码重置

请输入您的邮箱地址。 您将收到一个链接来创建新密码。

检查你的邮件中的确认链接。