Where do you want to put your custom product tabs? back-end or front-end?
What is the difference between the two?
The woocommerce hooks and filters are different for back-end and front-end.
In the back-end your are responsible to save them to post meta where in the front-end you just throw them to the session variables and let the woocommerce global take care the rest.
It will be backend then. I was able to make the custom field appear but it’s not where I want it to be. I used this
<?php if ( is_product() ) { the_meta(); } ?>
by adding it in the woocommerce.php
It’s showing up under the contents of the main product descriptions. I want it to be in the custom tab I’ve created. I am using a plugin that will allow me to add the custom details in bulk via csv files. Each product has different description (materials, dimensions, shipping weight).
Here’s the snippet code I used to create new tab. This snippet was placed using the code snippet plugin. If I can somehow add more codes in here to make the tabs grab the specific custom fields that would be great!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
I think you’re in the right track all you need to do is to double check the code and add the “the_meta” under woo_new_product_tab_content() or find out the “meta_key” and use the get_post_meta($post->ID, ‘shipping_meta_key’, true);
Plugin Contributor
royho
(@royho)
Within your woo_new_product_tab_content function you can do this.
global $post;
$product = wc_get_product( $post->ID );
$description = $post->post_content;
$shipping = $product->get_weight();
$custom_meta = get_post_meta( $post->ID, 'your_meta_key', true );
Hope that helps.
Thanks toknatz and Roy. Roy Is there any way I can add that code without touching the core files? Can I create a new snippet and add it in the code snippet plugin?
You may add that to your functions.php
Plugin Contributor
royho
(@royho)
Yes, all code should be added to your child theme’s functions.php file.