Created
March 15, 2017 10:38
-
-
Save vdwijngaert/b4603fb3ac376054a3a2f645ad58ff23 to your computer and use it in GitHub Desktop.
Populate ACF Select Field with WooCommerce Attributes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Populate ACF Select Field with WooCommerce Attributes. | |
*/ | |
add_filter('acf/load_field/name=featured_attributes', function($field) { | |
$taxonomies = get_taxonomies([ | |
'public' => false, | |
'_builtin' => false | |
], 'objects'); | |
$field['choices'] = []; | |
/** @var \WP_Taxonomy $taxonomy */ | |
foreach($taxonomies as $taxonomy) { | |
// Exclude non-woocommerce choices: | |
if(strncmp('pa_', $taxonomy->name, 3) !== 0) { | |
continue; | |
} | |
$field['choices'][$taxonomy->name] = $taxonomy->label; | |
} | |
return $field; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello ! Where do we have to put this in order to make it work ?