Dynamically create woocommerce tabs
-
Hello,
I want to create WooCommerce Tabs dynamically on basis of the product variation. So I do this:foreach ($variant_attributes as $variant_id => $variant_attribute) { $tabs[$variant_attribute['attribute_art']] = [ 'title' => $variant_attribute['attribute_art'], 'priority' => 16, 'callback' => 'custom_tab_content' ]; }
I am now asking myself how can I create the callback dynamically in order to show different content for each tabs? I need to have the variant_id in the tab contents to distinguish which content should be displayed.
I have a few questions:
1. Can I somehow pass data to my callback, so that the function is called as this
custom_tab_content($variant_id)
?2. I solved it like this, but I am sure that this is not the best solution (I am using eval here).
foreach ($variant_attributes as $variant_id => $variant_attribute) { $tabs[$variant_attribute['attribute_art']] = [ 'title' => $variant_attribute['attribute_art'], 'priority' => 16, 'callback' => 'custom_tab_content_'.$variant_attribute['attribute_art'] ]; eval('function custom_tab_content_'.$variant_attribute['attribute_art'].' () { echo '.$variant_attribute['attribute_art'].'; }'); }
Can you give guidance how I can solve this in the best way?
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Dynamically create woocommerce tabs’ is closed to new replies.