0

我正在为 wordpress 上的商店使用 woocommerce 插件 - woocommerce 为您注册了许多分类法。

我想将 show_in_nav_menus 设置更改为 true,但我听说修改核心文件的形式不好。

有没有办法在我的主题的functions.php中覆盖它 - 它下面代码的最后一个参数我需要更改为true

register_post_type( "product",
        array(
            'labels' => array(
                    'name'                  => __( 'Products', 'woocommerce' ),
                    'singular_name'         => __( 'Product', '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' ),
            'has_archive'           => $base_slug,
            'show_in_nav_menus'     => true
        )
    );
4

1 回答 1

0

你可以把它放在你的functions.php文件中,它会覆盖插件中的那个。请小心从 init 操作中调用它:

add_action( 'init', 'register_my_post_type' );
function register_my_post_type() {
   /* here */
}

并确保这将在您的插件初始化操作之后运行。也许它需要添加一个较低的优先级:

add_action( 'init', 'register_my_post_type', 1000 );
// 1000 -> lower priority, will run after the plugin init action
于 2012-05-10T12:19:15.380 回答