Created
August 20, 2016 13:18
-
-
Save hereswhatidid/9ba2bfe386a4eafb0bc82a11a748416b to your computer and use it in GitHub Desktop.
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 | |
class ACF_Product_Options { | |
static $slug = 'hwid_attributes'; | |
public static function init() { | |
// Gather the global attribute types | |
$attribute_terms = wc_get_attribute_taxonomy_names(); | |
// Initialize the array for holding the location rules | |
$group_filter = array(); | |
// Loop through the attribute types and build our field group location rules: IF this OR this OR this | |
foreach( $attribute_terms as $attribute_term ) { | |
$group_filter[] = array( array( | |
'param' => 'taxonomy', | |
'operator' => '==', | |
'value' => $attribute_term, | |
'order_no' => 0, | |
'group_no' => 0, | |
) ); | |
} | |
if ( function_exists( 'acf_add_local_field_group' ) ) { | |
acf_add_local_field_group( array( | |
'key' => self::$slug, | |
'title' => __( 'Product Options', 'custom-site' ), | |
'fields' => array( | |
array ( | |
'key' => self::$slug . 'imagestab', | |
'label' => __( 'Images', 'custom-site' ), | |
'type' => 'tab', | |
), | |
array ( | |
'key' => self::$slug . 'detail', | |
'label' => __( 'Detail Image', 'custom-site' ), | |
'name' => 'detail_image', | |
'type' => 'image', | |
'instructions' => 'This image should have a transparent background.', | |
'return_format' => 'array', | |
'preview_size' => 'thumbnail', | |
'library' => 'images', | |
), | |
), | |
// Use the custom location rules to target all global attribute Edit pages | |
'location' => $group_filter, | |
'options' => array( | |
'position' => 'normal', | |
'layout' => 'default', | |
'hide_on_screen' => array(), | |
), | |
'menu_order' => 0, | |
) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Mate! I copy pasted this code in functions.php file and it didn't do anything.