Created
August 12, 2018 14:17
-
-
Save guytzhak/aaa61fa77e1e9117d14f0c65282ad028 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 | |
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