Skip to content

Instantly share code, notes, and snippets.

@gmmedia
Last active January 17, 2024 13:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gmmedia/b895225d3eefb42bdfc573836b776b86 to your computer and use it in GitHub Desktop.
Save gmmedia/b895225d3eefb42bdfc573836b776b86 to your computer and use it in GitHub Desktop.
Enable Gutenberg editor for WooCommerce
<?php
// Find the description at https://bloggerpilot.com/en/gutenberg-for-woocommerce/
// Disable new WooCommerce product template (from Version 7.7.0)
function bp_reset_product_template($post_type_args) {
if (array_key_exists('template', $post_type_args)) {
unset($post_type_args['template']);
}
return $post_type_args;
}
add_filter('woocommerce_register_post_type_product', 'bp_reset_product_template');
// Enable Gutenberg editor for WooCommerce
function bp_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', 'bp_activate_gutenberg_product', 10, 2);
// Enable taxonomy fields for woocommerce with gutenberg on
function bp_enable_taxonomy_rest($args) {
$args['show_in_rest'] = true;
return $args;
}
add_filter('woocommerce_taxonomy_args_product_cat', 'bp_enable_taxonomy_rest');
add_filter('woocommerce_taxonomy_args_product_tag', 'bp_enable_taxonomy_rest');
add_filter( 'woocommerce_taxonomy_args_product_tag', 'j0e_enable_taxonomy_rest' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment