3

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.com/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?

13

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.

  • 1
    Do you know if this still works for WooCommerce 3+? I cannot make it to work – Israel Ortuño Feb 11 at 18:55
  • Thank, the solution works, unfortunately it only tracks the product post content and not product data, prices or other specific product fields. – Jackie Degl'Innocenti Feb 13 at 12:10
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.