如何以编程方式将属性注册到Woocommerce

chr*_*ony 1 woocommerce

我不是在谈论为产品添加属性,但我想添加一个属性本身..

你可以从产品 - >属性下的UI,但从代码中完成它(ei:要调用哪些函数或更新表)?

hel*_*ing 5

属性只是一个自定义分类法,所以我认为你应该能够像注册任何自定义分类法一样执行此操作.WooCommerce将他们的属性分类名称加上'pa_'(可能代表产品属性)

add_action( 'init', 'create_product_attribute' );

function create_product_attribute() {
    register_taxonomy(
        'pa_genre',
        'product',
        array(
            'label' => __( 'Genre' ),
            'rewrite' => array( 'slug' => 'genre' ),
            'hierarchical' => true,
        )
    );
}
Run Code Online (Sandbox Code Playgroud)