Skip to content

Instantly share code, notes, and snippets.

@lukecav
Forked from hereswhatidid/wooattributes-acf.php
Created June 22, 2017 16:49
Show Gist options
  • Select an option

  • Save lukecav/596e7dc270cd890ab48d89aa0ea24b4b to your computer and use it in GitHub Desktop.

Select an option

Save lukecav/596e7dc270cd890ab48d89aa0ea24b4b 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,
) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment