Forked from vdwijngaert/acf-select-wc-attributes.php
Created
October 13, 2021 13:59
-
-
Save mshshuvooo/38dc028b2482140a75c59b32ebf390e2 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