filters - Adding revision support to WooCommerce product content

I need to add revision support to WooCommerce Products (at least for the main content). The developers are unwilling to

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 badges
Add a comment  | 

2 Answers 2

Reset to default 17

As 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744756436a4591911.html

相关推荐

  • filters - Adding revision support to WooCommerce product content

    I need to add revision support to WooCommerce Products (at least for the main content). The developers are unwilling to

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信