Skip to content

Instantly share code, notes, and snippets.

@guytzhak
Created August 12, 2018 14:17
Show Gist options
  • Save guytzhak/aaa61fa77e1e9117d14f0c65282ad028 to your computer and use it in GitHub Desktop.
Save guytzhak/aaa61fa77e1e9117d14f0c65282ad028 to your computer and use it in GitHub Desktop.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
add_action('acf/init', 'ofert_acf_add_local_field_groups');
function ofert_acf_add_local_field_groups() {
//$screen = get_current_screen();
$post_id = isset( $_GET['post'] ) && !empty($_GET['post']) ? sanitize_text_field($_GET['post']) : false;
if( !$post_id ) {
return;
}
$product = new WC_Product_Variable($post_id);
$childs = $product->get_children();
foreach ($childs as $child) {
/*$fields[] = [
'key' => 'variation_tab_'. $child,
'label' => get_the_title($child),
'name' => '',
'type' => 'tab',
'placement' => 'left',
'endpoint' => 0,
];*/
$fields[] = [
'key' => 'variation_title_'. $child,
'label' => 'Title',
'name' => 'variation_title_'. $child,
'type' => 'text',
];
$fields[] = [
'key' => 'variation_gallery_'. $child,
'label' => 'Gallery',
'name' => 'variation_gallery_'. $child,
'type' => 'gallery',
];
}
acf_add_local_field_group(
[
'key' => 'single_product_variations_galleries',
'title' => 'Variations Galleries',
'fields' => $fields,
'location' => [
[
[
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
],
],
],
]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment