WooCommerce:为产品指定一个“作者”

时间:2012-11-27 作者:pixeline

我正在为woocommerce开发我的第一个主题。

我需要能够将“作者”(真正的“设计师”)分配给woocommerce产品。这可行吗?我曾考虑使用wordpress内置的“author”用户,但产品编辑界面不提供“author”框,这与“post”编辑界面不同。

1 个回复
最合适的回答,由SO网友:brasofilo 整理而成

简单使用add_post_type_support:

add_action(\'init\', \'wpse_74054_add_author_woocommerce\', 999 );

function wpse_74054_add_author_woocommerce() {
    add_post_type_support( \'product\', \'author\' );
}
User assigned with custom role

user role

<小时>Authors enabled in Products post type

woo products with author enabled

另一个选择,我不确定its correctness, 要钩住它woocommerce_register_post_type*register 首先是post类型。这是原始函数加上所需变量的副本author 附加到supports 论点

wp内容/插件/woocommerce/woocommerce。php,第885行

add_action( \'woocommerce_register_post_type\', \'wpse_74054_override_register_product_type\' );
function wpse_74054_override_register_product_type()
{
    $shop_page_id = woocommerce_get_page_id(\'shop\');
    $base_slug = ( $shop_page_id > 0 && get_page( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : \'shop\';
    $product_base = ( get_option(\'woocommerce_prepend_shop_page_to_products\') == \'yes\' ) ? trailingslashit($base_slug) : trailingslashit(_x(\'product\', \'slug\', \'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\' )
                ),
            \'description\'           => __( \'This is where you can add new products to your store.\', \'woocommerce\' ),
            \'public\'                => true,
            \'show_ui\'               => true,
            \'capability_type\'       => \'post\',
            \'capabilities\' => array(
                \'publish_posts\'         => \'manage_woocommerce_products\',
                \'edit_posts\'            => \'manage_woocommerce_products\',
                \'edit_others_posts\'     => \'manage_woocommerce_products\',
                \'delete_posts\'          => \'manage_woocommerce_products\',
                \'delete_others_posts\'   => \'manage_woocommerce_products\',
                \'read_private_posts\'    => \'manage_woocommerce_products\',
                \'edit_post\'             => \'manage_woocommerce_products\',
                \'delete_post\'           => \'manage_woocommerce_products\',
                \'read_post\'             => \'manage_woocommerce_products\'
            ),
            \'publicly_queryable\'    => true,
            \'exclude_from_search\'   => false,
            \'hierarchical\'          => false, // Hierarcal causes memory issues - WP loads all records!
            \'rewrite\'               => array( \'slug\' => $product_base, \'with_front\' => false, \'feeds\' => $base_slug ),
            \'query_var\'             => true,
            \'supports\'              => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\', \'comments\', \'custom-fields\', \'page-attributes\', \'author\' ),
            \'has_archive\'           => $base_slug,
            \'show_in_nav_menus\'     => true
        )
    );
}

结束

相关推荐

why is there an author.php

为什么有作者。php文件时,相同的信息是在单一的。php?我查看了模板层次结构,人们会认为如果作者。php不存在,单一。php将发挥作用,但它没有。我还认为,如果你为作者设置样式。php会影响页面上的作者简历,但事实并非如此。所以我想把作者简历一起删除。也许把它变成一个函数并在我的页面中调用它。你觉得怎么样?