Woocommerce 填充商业类别

Woocommerce 填充商业类别,woocommerce,product,categories,Woocommerce,Product,Categories,我正在尝试将Woocommerce产品类别自动填充到下拉表单字段中。这段代码在我试用Wordpress类别时起作用,但现在没有填充WoodCommerce类别。在试用Wordpress post时,我使用“post”作为“type”,使用“categories”作为“taxonomy” add_filter('frm_setup_new_fields_vars', 'frm_populate_int_categories', 20, 2); add_filter('frm_setup_edit_

我正在尝试将Woocommerce产品类别自动填充到下拉表单字段中。这段代码在我试用Wordpress类别时起作用,但现在没有填充WoodCommerce类别。在试用Wordpress post时,我使用“post”作为“type”,使用“categories”作为“taxonomy”

add_filter('frm_setup_new_fields_vars', 'frm_populate_int_categories', 20, 2);
add_filter('frm_setup_edit_fields_vars', 'frm_populate_int_categories', 20, 2);
function frm_populate_int_categories( $values, $field ) {
    if ( $field->id == 683 ) { //replace 125 with the ID of the field to populate

    // Adjust your category aruments as needed
    $category_args = array(
        'orderby' => 'name',
        'order' => 'ASC',
        'hide_empty' => false,
        'exclude' => array(232, 277),
        'type' => 'product',
        'taxonomy' => 'product_cat',
    );

    $categories = get_categories( $category_args );

    unset( $values['options'] );
    $values['options'] = array( '' ); //remove this line if you are using a checkbox or radio field

    foreach( $categories as $category ){
        $values['options'][ $category->term_id ] = $category->name;
    }

    $values['use_key'] = true; //this will set the field to save the category ID
    }

    return $values;
}

我已将“类型”更改为“产品”,将“分类法”更改为“产品类别”,但它似乎仍然不起作用。

有人能帮忙吗?不用担心。我已经解决了这个问题。