向WooCommerce产品内容添加修订支持

时间:2016-09-11 作者:douglaz

我需要添加对WooCommerce产品的修订支持(至少对主要内容)。开发人员不愿意这样做,除非Wordpress支持额外的产品字段:https://github.com/woothemes/woocommerce/issues/2178

由于我更喜欢部分修订支持,而不是什么都不支持,我四处看看,发现了以下内容。

从WooCommerce 2.6.4开始,我们在WooCommerce/includes/class wc帖子类型上有此功能。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
                        )
                )
        );
我可以通过添加\'revisions\'\'supports\' 大堆

但每次升级都会恢复此更改。

现在的问题是:如何将此更改作为子主题/插件/任何可以在WooCommerce升级后继续工作的东西?

2 个回复
最合适的回答,由SO网友:Roy Ho 整理而成

正如你所指出的,已经有了一个过滤器。

add_filter( \'woocommerce_register_post_type_product\', \'wpse_modify_product_post_type\' );

function wpse_modify_product_post_type( $args ) {
     $args[\'supports\'][] = \'revisions\';

     return $args;
}
把它放在你孩子的主题函数中。php文件。

SO网友:Rohit Savaj

在页面编辑屏幕中启用修订元框。

function wpcodex_add_excerpt_support_for_pages() {
    add_post_type_support( \'product\', \'revisions\' );
}
add_action( \'init\', \'wpcodex_add_excerpt_support_for_pages\' );
这可能会有所帮助

相关推荐

绕过WP查询中的“supress_Filters”

显然,出于某种不合逻辑的原因,开发人员决定获取所有语言帖子的唯一方法是添加supress_filters=true 到WP\\u查询(而不是像这样language_code=all 选项)。无论如何,我的情况是,我需要获取所有语言的帖子,但也需要使用过滤器修改WP\\u查询。有没有办法强制将我的过滤器添加到查询中,即使supress_filters 设置为false?这是我需要添加的过滤器:add_filter( \'posts_where\', function($where, $wp_query) {