【问题标题】:Change custom Product taxonomy to WooCommerce Product Taxonomy将自定义产品分类更改为 WooCommerce 产品分类
【发布时间】:2019-11-12 12:41:54
【问题描述】:

我正在使用工具集类型生成“产品”帖子类型和“产品类别”分类(产品类别)的网站。现在我将 WooCommerce 添加到站点,需要将“产品类别”分类设置为产品的 WooCommerce 分类,product_cat。 WooCommerce 已经选择了产品帖子类型,并且所有产品都显示在 WooCommerce 产品中。我只需要让类别也出现在那里。

我尝试使用名为 Taxonomy Switcher 的插件以及更新 wp_term_taxonomy 表中的分类字段的 SQL 查询。这两个都将产品类别移动到 product_cat 但仅适用于父类别,删除子类别。

UPDATE wp_term_taxonomy SET taxonomy='genre' WHERE taxonomy='category'

如何将自定义产品类别分类法更改为 WooCommerce 产品分类法 product_cat?

【问题讨论】:

    标签: mysql wordpress woocommerce


    【解决方案1】:
    add_action( 'init', 'create_product_taxonomies', 0 );
    
    function create_product_taxonomies() {
        $labels = array(
            'name'              => _x( 'Genre', 'taxonomy general name', 'textdomain' ),
            'singular_name'     => _x( 'Genres', 'taxonomy singular name', 'textdomain' ),
            'search_items'      => __( 'Search Genres', 'textdomain' ),
            'all_items'         => __( 'All Genre', 'textdomain' ),
            'parent_item'       => __( 'Parent Genres', 'textdomain' ),
            'parent_item_colon' => __( 'Parent Genres:', 'textdomain' ),
            'edit_item'         => __( 'Edit Genres', 'textdomain' ),
            'update_item'       => __( 'Update Genres', 'textdomain' ),
            'add_new_item'      => __( 'Add New Genres', 'textdomain' ),
            'new_item_name'     => __( 'New Genre Name', 'textdomain' ),
            'menu_name'         => __( 'Genres', 'textdomain' ),
        );
    
        $args = array(
            'hierarchical'      => true,
            'labels'            => $labels,
            'show_ui'           => true,
            'show_admin_column' => true,
            'query_var'         => true,
            'rewrite'           => array( 'slug' => 'genres' ),
        );
    
        register_taxonomy( 'genre', array( 'product' ), $args );
    
    
    }
    

    【讨论】:

    • 感谢您的回复。我可以通过禁用 WooCommerce、将工具集类型中的“产品类别”分类更改为 WooCommerce 分类“product_cat”、禁用工具集类型然后重新激活 WooCommerce 来解决我的问题。
    猜你喜欢
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 2017-02-06
    • 2017-11-13
    • 2019-06-15
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多