WooCommerce是WordPress的開源電子商務(wù)插件,Woo的產(chǎn)品頁面內(nèi)容編輯區(qū)默認(rèn)是不支持Elementor免費(fèi)版(需升級PRO)與Gutenberg塊編輯器。所以,今天教大家通過一段代碼輕松讓W(xué)ooCommerce產(chǎn)品頁支持古騰堡編輯器。
一、代碼如下:
// Enable Gutenberg editor for WooCommerce
function j0e_activate_gutenberg_product( $can_edit, $post_type ) {
if ( $post_type == 'product' ) {
$can_edit = true;
}
return $can_edit;
}
add_filter( 'use_block_editor_for_post_type', 'j0e_activate_gutenberg_product', 10, 2 );
// enable taxonomy fields for woocommerce with gutenberg on
function j0e_enable_taxonomy_rest( $args ) {
$args['show_in_rest'] = true;
return $args;
}
add_filter( 'woocommerce_taxonomy_args_product_cat', 'j0e_enable_taxonomy_rest' );
add_filter( 'woocommerce_taxonomy_args_product_tag', 'j0e_enable_taxonomy_rest' );
二、使用方法:
將以上代碼復(fù)制粘貼到網(wǎng)站模板主題目錄下 functions.php 文件中并保存,重新刷新頁面并編輯產(chǎn)品詳情頁,你會發(fā)現(xiàn)已經(jīng)激活了WooCommerce使用WordPress塊編輯器功能,過程簡單便捷。