Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
Created August 20, 2016 13:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hereswhatidid/9ba2bfe386a4eafb0bc82a11a748416b to your computer and use it in GitHub Desktop.
Save hereswhatidid/9ba2bfe386a4eafb0bc82a11a748416b to your computer and use it in GitHub Desktop.
<?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,
) );
}
}
}
@SahilMepani
Copy link

Hey Mate! I copy pasted this code in functions.php file and it didn't do anything.

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