admin管理员组文章数量:1391934
I need to add revision support to WooCommerce Products (at least for the main content). The developers are unwilling to do this until there is some support on Wordpress for the extra product fields:
As I prefer partial revision support than nothing, I took a look around and found the following.
As of WooCommerce 2.6.4, we have this on woocommerce/includes/class-wc-post-types.php:
register_post_type( 'product',
apply_filters( 'woocommerce_register_post_type_product',
array(
'labels' => array(
'name' => __( 'Products', 'woocommerce' ),
'singular_name' => __( 'Product', 'woocommerce' ),
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add Product', 'woocommerce' ),
'add_new_item' => __( 'Add New Product', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Product', 'woocommerce' ),
'new_item' => __( 'New Product', 'woocommerce' ),
'view' => __( 'View Product', 'woocommerce' ),
'view_item' => __( 'View Product', 'woocommerce' ),
'search_items' => __( 'Search Products', 'woocommerce' ),
'not_found' => __( 'No Products found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Products found in trash', 'woocommerce' ),
'parent' => __( 'Parent Product', 'woocommerce' ),
'featured_image' => __( 'Product Image', 'woocommerce' ),
'set_featured_image' => __( 'Set product image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),
'use_featured_image' => __( 'Use as product image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into product', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),
'filter_items_list' => __( 'Filter products', 'woocommerce' ),
'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),
'items_list' => __( 'Products list', 'woocommerce' ),
),
'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'product',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'rewrite' => $product_permalink ? array( 'slug' => untrailingslashit( $product_permalink ), 'with_front' => false, 'feeds' => true ) : false,
'query_var' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'publicize', 'wpcom-markdown' ),
'has_archive' => ( $shop_page_id = wc_get_page_id( 'shop' ) ) && get_post( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop',
'show_in_nav_menus' => true
)
)
);
I can make it work adding a 'revisions'
to 'supports'
array.
But every upgrade will revert this change.
Now the question is: how to make this change as a child theme/plugin/whatever that can keep working even after WooCommerce upgrades?
I need to add revision support to WooCommerce Products (at least for the main content). The developers are unwilling to do this until there is some support on Wordpress for the extra product fields: https://github/woothemes/woocommerce/issues/2178
As I prefer partial revision support than nothing, I took a look around and found the following.
As of WooCommerce 2.6.4, we have this on woocommerce/includes/class-wc-post-types.php:
register_post_type( 'product',
apply_filters( 'woocommerce_register_post_type_product',
array(
'labels' => array(
'name' => __( 'Products', 'woocommerce' ),
'singular_name' => __( 'Product', 'woocommerce' ),
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add Product', 'woocommerce' ),
'add_new_item' => __( 'Add New Product', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Product', 'woocommerce' ),
'new_item' => __( 'New Product', 'woocommerce' ),
'view' => __( 'View Product', 'woocommerce' ),
'view_item' => __( 'View Product', 'woocommerce' ),
'search_items' => __( 'Search Products', 'woocommerce' ),
'not_found' => __( 'No Products found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Products found in trash', 'woocommerce' ),
'parent' => __( 'Parent Product', 'woocommerce' ),
'featured_image' => __( 'Product Image', 'woocommerce' ),
'set_featured_image' => __( 'Set product image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),
'use_featured_image' => __( 'Use as product image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into product', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),
'filter_items_list' => __( 'Filter products', 'woocommerce' ),
'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),
'items_list' => __( 'Products list', 'woocommerce' ),
),
'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'product',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'rewrite' => $product_permalink ? array( 'slug' => untrailingslashit( $product_permalink ), 'with_front' => false, 'feeds' => true ) : false,
'query_var' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'publicize', 'wpcom-markdown' ),
'has_archive' => ( $shop_page_id = wc_get_page_id( 'shop' ) ) && get_post( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop',
'show_in_nav_menus' => true
)
)
);
I can make it work adding a 'revisions'
to 'supports'
array.
But every upgrade will revert this change.
Now the question is: how to make this change as a child theme/plugin/whatever that can keep working even after WooCommerce upgrades?
Share Improve this question edited Sep 12, 2016 at 1:39 Mark Kaplun 23.8k7 gold badges43 silver badges65 bronze badges asked Sep 11, 2016 at 22:27 douglazdouglaz 1531 gold badge1 silver badge5 bronze badges2 Answers
Reset to default 17As you pointed out already there is a filter.
add_filter( 'woocommerce_register_post_type_product', 'wpse_modify_product_post_type' );
function wpse_modify_product_post_type( $args ) {
$args['supports'][] = 'revisions';
return $args;
}
Put that in your child theme's functions.php file.
Enables the revisions meta box in Page edit screen.
function wpcodex_add_excerpt_support_for_pages() {
add_post_type_support( 'product', 'revisions' );
}
add_action( 'init', 'wpcodex_add_excerpt_support_for_pages' );
this may help
本文标签: filtersAdding revision support to WooCommerce product content
版权声明:本文标题:filters - Adding revision support to WooCommerce product content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744756436a2623492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论