获取用户创建的WooCommerce属性(分类)

时间:2016-02-19 作者:Justin W Hall

在管理端生成metabox数据。

function prod_a( $value ){
    global $post;
    global $product; // This === null. Thus the query bellow. 
    $args = array(
         \'post_type\'     => \'product_variation\',
         \'post_status\'   => array( \'private\', \'publish\' ),
         \'numberposts\'   => -1,
         \'orderby\'       => \'menu_order\',
         \'order\'         => \'asc\',
         \'post_parent\'   => $post->ID
    );
    $variations = get_posts( $args );
    foreach ($variations as $v) {
        $meta = get_post_taxonomies($post->ID );
        var_dump($meta);
    }
    ...
}
转储包含所有已注册分类的数组。看起来像:

array (size=8)
0 => string \'product_type\' (length=12)
1 => string \'product_cat\' (length=11)
2 => string \'product_tag\' (length=11)
3 => string \'product_shipping_class\' (length=22)
4 => string \'pa_finish\' (length=9)
5 => string \'pa_collars\' (length=10)
6 => string \'pa_mounting\' (length=11)
7 => string \'pa_sizing\' (length=9)
我可以处理这些结果,但我真正想要的是添加什么分类法,而不是用户。具有“pa\\uU”前缀的分类法。

1 个回复
最合适的回答,由SO网友:Justin W Hall 整理而成
function prod_a( $value ){
    global $post;
    $_pf = new WC_Product_Factory();  
    $_product = $_pf->get_product($post->ID);
    $available_variations = $_product->get_available_variations();
    var_dump($available_variations);
}

相关推荐