2013-08-07 54 views
0

我真的希望有人能尽快帮助我解决这个问题。如何在woocommerce wordpress中添加产品类别

好的,我正在为用户构建一个costum脚本来发布一个新产品,我有一切工作和插入成功(事件照片),但似乎无法找到任何代码应该用来更新帖子类别,因为它具有“product_cat”(woocommerce产品类别)的分类标准,因此它不属于正常类别。

任何想法?

以下工作的非:($ term_id是涉及某种产品的“product_cat”的term_id)

 
    wp_set_post_terms($post_id, array($term_id), "product_cat"); 
    wp_set_post_terms($post_id, (int)$term_id, "product_cat"); 
    update_post_meta($post_id,'product_cat',$term_id); 

我已经试过别人,但他们只是不似乎做任何事情,一些功能甚至创建一个新的类别与ID ...

回答

4

那么我测试与wp_set_post_terms($post_id, array($term_id), "product_cat");并为我工作。

0

尝试wp_insert_term

wp_insert_term(
    'New Category', // the term 
    'product_cat', // the taxonomy 
    array(
    'description'=> 'Category description', 
    'slug' => 'new-category' 
) 
); 
相关问题