Carbon-fields: retrieve woocoomerce product categories in select field

Created on 11 Apr 2017  路  3Comments  路  Source: htmlburger/carbon-fields

I'm trying to use carbon fields to retrieve a list of product categories from woocomerce in a select but hooking the fields registration on the init with 0 priority makes this impossible since the product_cat taxonomy is registered later and it's trowing me an "Invalid Taxonomy" error.
Can you please tell me if removing the 0 priority will brake anything in the plugin or if there it's another solution to make this work?

[type] question

All 3 comments

Select field supports callback. For any options that are not static, is recommended to load with callback, since this improves performance with a lot when listing all posts or in your case - all terms.

https://carbonfields.net/docs/fields-select/

Thank you for sharing the knowledge, it works.

Just to add an example to what @pkostadinov-2create said (for future reference):

// your options file ...
Field::make( 'select', 'crb_category', 'Category' )
    ->add_options( 'my_product_categories_options' )

// somewhere in functions.php, for example ...
function my_product_categories_options() {
    $category_options = [array: term id => term name];
    return $category_options;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

proweb picture proweb  路  3Comments

halvardos picture halvardos  路  3Comments

Obvio picture Obvio  路  4Comments

ArekZw picture ArekZw  路  4Comments

jquimera picture jquimera  路  4Comments