I don’t believe that’s possible out-of-the-box because a multisite is a network of multiple wordpress instances with different database tables. Using ACF JSON helps synching the field groups rather easily.
Is this also possible with a repeater field?
So, i got this working eventually.
Yet it is only like 15% ACF and the rest is WordPress core functions and JS.
If anyone is interested in the code, let me know. Furthermore, i think it would be nice if we as a community can get a full ACF solution in the future.
Anyway, thanks for all the help!
if ($value == 'choice1') {
// do x
} elseif ($value == 'choice2') {
// do y
}
This won’t work because the button group values are created dynamically from the options page and therefore the values cannot be known beforehand. I’m started to think it’s not possible because there isn’t any example found anywhere. This question was also never answered properly with code.
It is actually a similar question like this one: https://support.advancedcustomfields.com/forums/topic/generate-fields-for-each-select-option/
I’m now down to the point where i need some kind of code to do this:
If the radio button does not have choices when you edit the field group then youβll need to create acf/prepare_field filters for each of these fields and dynamically create the conditional logic.
What’s hard to grasp for me:
The wysiwyg field needs to be different for every button group selection, but what about the field key? This needs to be the same every time?
I understand the php export with the arrays but not how to code the conditional logic with the wysiwyg field.
i.e.
1) I select ‘button one’ from the button group in the product edit page.
2) A wysiwyg field is show where i enter some value
3) I select ‘button two’ from the button group and enter some value
4) Echo this in the tab content (with just the_field('field_name');?
So i exported the field group with it’s conditional wysywig field based on the choice in the button group to php:
if (function_exists('acf_add_local_field_group')) :
acf_add_local_field_group(array(
'key' => 'group_xxxxxxxxxx',
'title' => 'The product tabs',
'fields' => array(
array(
'key' => 'field_of_the_product_tabs_xxxxx',
'label' => 'The tabs',
'name' => 'the_tabs',
'type' => 'button_group',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
// These choices are generated by the repeater with a text subfield from the option page
'choices' => array(
'choice1' => 'choice1',
'choice2' => 'choice2',
),
'allow_null' => 0,
'default_value' => '',
'layout' => 'horizontal',
'return_format' => 'value',
),
// So this wysywig field needs to be created everytime a choice is added from the option page
// Corresponding to the selected button group choice
array(
'key' => 'field_xxxxxxxx',
'label' => 'product tab content',
'name' => 'pro_tab_content',
'type' => 'wysiwyg',
'instructions' => '',
'required' => 0,
// array van conditional logic ie.
'conditional_logic' => array(
array(
array(
'field' => 'field_of_the_product_tabs_xxxxx',
'operator' => '==',
'value' => 'choice1', // the selected button group choice ie. choice1, choice2...
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
'delay' => 0,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
));
endif;
I think i’m missing some skills or knowledge because i can’t wrap my head around in how to create a wysiwyg field specific for it’s product tab.
A ‘static’ field and displaying that in the tab content is easy, but then every tab has the same value π
/* --
WooCommerce Tabs content
-- */
function woo_tab_content($slug, $tab)
{
// the content in this function is display in the WooCommerce tabs
}
I understand, thank you for your time.
It sounds somewhat complicated, but probably isn’t π
I will look into it.
This is the current code i have in functions.php;
/* --
ACF Option page
-- */
if (function_exists('acf_add_options_page')) {
// Main
acf_add_options_page(array(
'page_title' => 'Product tabs',
'menu_title' => 'Product tabs',
'menu_slug' => 'acf-product-tabs',
'capability' => 'edit_posts',
'icon_url' => 'dashicons-table-row-after',
'redirect' => true,
'position' => '20.0'
));
}
/* --
WooCommerce Tabs
-- */
add_filter('woocommerce_product_tabs', 'woo_dynamic_tabs');
function woo_dynamic_tabs($tabs)
{
if (have_rows('repeater_field_name', 'option')) :
while (have_rows('repeater_field_name', 'option')) : the_row();
$woo_tab_label = get_sub_field('repeater_sub_field');
// Attributen tab
$tabs['attrib_' . strtolower($woo_tab_label) . '_tab'] = array(
'title' => __($woo_tab_label, 'woocommerce'),
'priority' => 100,
'callback' => 'woo_tab_content'
);
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
// return
return $tabs;
}
/* --
Fill button group
-- */
add_filter('acf/load_field/key=field_xxxxxxxxxxx', function ($field) {
// Add options to select field
$field['choices'] = array();
// Dynamic data
$created_tabs = get_field('repeater_field_name', 'option');
foreach ($created_tabs as $new_tab) {
$field['choices'][$new_tab['repeater_sub_field']] = $new_tab['repeater_sub_field'];
}
return $field;
});
/* --
WooCommerce Tabs content
-- */
function woo_tab_content($slug, $tab)
{
// Dynamic creation of wysiwig fields for single product
// How?
}
Yes, exactly.
The field to be generated / displayed is a wysiwyg field. The values ββin that field are then shown in the appropriate tab. The functionality should be the same as this plugin. I just prefer to do this in ACF of course π
Or, if there’s a more efficient method of achieving above requirements, let me know!
You could use a radio list where you style the buttons into a star.
Also, look at https://www.advancedcustomfields.com/resources/create-a-front-end-form/ for creation of the front-end form.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.