Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mshshuvooo/38dc028b2482140a75c59b32ebf390e2 to your computer and use it in GitHub Desktop.
Save mshshuvooo/38dc028b2482140a75c59b32ebf390e2 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;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment