我正在尝试将Woocommerce产品类别自动填充到下拉表单字段中 . 这个代码在我使用Wordpress类别进行试用时起了作用,但现在却没有填充Woocommerce类 . 在使用Wordpress帖子进行试用时,我将“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;
}

我已将“type to”product“和”taxonomy“更改为”product_cat“,但它似乎仍然无效 .