显示Woocommerce中父级产品的子类别

时间:2015-09-19 13:50:03

标签: php wordpress plugins woocommerce

我正试着在管理面板下找到一种方便管理我的产品类别的方法。

目前,所有类别都列在同一位置下。我需要的是当我点击父类别时,我可以看到所有子类别并能够添加新的子类别。

enter image description here

2 个答案:

答案 0 :(得分:1)

现在使用免费插件:https://wordpress.org/plugins/product-category-tree/。这些天尝试和测试它并按预期工作。

附言老问题,但我一直在寻找相同的答案,但没有找到 - 希望它也能帮助其他人

答案 1 :(得分:0)

使用以下代码

    add_action('save_post', 'assign_parent_terms', 10, 2);

    function assign_parent_terms($post_id, $post){

        if($post->post_type != 'product')
            return $post_id;

        // get all assigned terms   
        $terms = wp_get_post_terms($post_id, 'product_cat' );
        foreach($terms as $term){
            while($term->parent != 0 && !has_term( $term->parent, 'product_cat', $post )){
                // move upward until we get to 0 level terms
                wp_set_post_terms($post_id, array($term->parent), 'product_cat', true);
                $term = get_term($term->parent, 'product_cat');
            }
        }

    }

上面的代码也会将子类别产品分配到父类别

相关问题