<?php
// Create additional info Tab
add_filter('woocommerce_product_data_tabs', 'LCLPC_additional_product_settings_tabs');
function LCLPC_additional_product_settings_tabs($tabs)
{
$tabs['additionnal'] = array(
'label' => 'Additional info',
'target' => 'additional_product_data',
'class' => ['hide_if_external'],
'priority' => 21
);
return $tabs;
}
// Additional info Tab content in back-end
add_action('woocommerce_product_data_panels', 'additional_product_panels');
function additional_product_panels()
{
echo '<div id="additional_product_data" class="panel woocommerce_options_panel hidden">';
woocommerce_wp_textarea_input(array(
'id' => 'usage',
'value' => get_post_meta(get_the_ID(), 'usage', true),
'label' => 'Usage',
));
woocommerce_wp_textarea_input(array(
'id' => 'storage',
'value' => get_post_meta(get_the_ID(), 'storage', true),
'label' => 'Storage',
));
woocommerce_wp_text_input(array(
'id' => 'allergens',
'value' => get_post_meta(get_the_ID(), 'allergens', true),
'label' => 'Allergen warnings',
));
woocommerce_wp_textarea_input(array(
'id' => 'ingredients',
'value' => get_post_meta(get_the_ID(), 'ingredients', true),
'label' => 'Ingredients',
));
woocommerce_wp_text_input(array(
'id' => 'supplier',
'value' => get_post_meta(get_the_ID(), 'supplier', true),
'label' => 'Supplier',
));
woocommerce_wp_text_input(array(
'id' => 'origin',
'value' => get_post_meta(get_the_ID(), 'origin', true),
'label' => 'Origin',
));
echo '</div>';
}
//Save
add_action('woocommerce_process_product_meta', function ($post_id) {
$product = wc_get_product($post_id);
$product->update_meta_data('usage', sanitize_text_field($_POST['usage']));
$product->update_meta_data('ingredients', sanitize_text_field($_POST['ingredients']));
$product->update_meta_data('allergens', sanitize_text_field($_POST['allergens']));
$product->update_meta_data('supplier', sanitize_text_field($_POST['supplier']));
$product->update_meta_data('storage', sanitize_text_field($_POST['storage']));
$product->update_meta_data('origin', sanitize_text_field($_POST['origin']));
$product->save();
});
Hi,
So I have two tiny problems with the plug-in:
I guess this might have to do with the way I save out the meta fields, but I haven't been able to figure out how to do it so it works:
Thank you!