I am trying to create a an array of WooCommerce product categories to use as a dropdown in the Customizer. The following code is working in a function hooked to ‘customize_register’ but not in functions.php
Unfortunately I need to create an array in functions.php
$woo_cat_args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'hide_empty' => 0,
);
$woo_categories = get_categories( $woo_cat_args );
In functions.php I am getting an empty array, but in the function hooked to ‘customize_register’ I am getting the WooCommerce categories.
So how can I get the categories in functions.php?