Skip to content

Instantly share code, notes, and snippets.

@vdwijngaert
Created March 15, 2017 10:38
Show Gist options
  • Save vdwijngaert/b4603fb3ac376054a3a2f645ad58ff23 to your computer and use it in GitHub Desktop.
Save vdwijngaert/b4603fb3ac376054a3a2f645ad58ff23 to your computer and use it in GitHub Desktop.
Populate ACF Select Field with WooCommerce Attributes.
<?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;
});
@rgaborieau
Copy link

Hello ! Where do we have to put this in order to make it work ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment