Created
February 21, 2023 04:14
-
-
Save daomapsieucap/eb00cda5a969ca02d4356770dc4cd277 to your computer and use it in GitHub Desktop.
Populating Woocommerce product attributes to ACF
This file contains hidden or 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 | |
| /** | |
| * Populating Product Attributes | |
| */ | |
| add_filter('acf/load_field/name=woo_admin_attributes', 'dc_acf_product_attribute'); | |
| function dc_acf_product_attribute($field){ | |
| $product_taxonomies = get_taxonomies([ | |
| '_builtin' => false, | |
| ]); | |
| $all_taxonomies = get_taxonomies([], 'object'); | |
| $taxonomies = []; | |
| if(!empty($product_taxonomies)){ | |
| foreach($product_taxonomies as $slug){ | |
| if(strpos($slug, 'pa_') !== false){ | |
| $taxonomies[$slug] = $all_taxonomies[$slug]; | |
| } | |
| } | |
| } | |
| foreach($taxonomies as $slug => $taxonomy){ | |
| $field['choices'][$slug] = $taxonomy->label; | |
| } | |
| return $field; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment