Insert Custom Field into Custom Tab
-
I haven’t been able to find this solution anywhere. Would anyone know how to insert a products custom field into a custom tab for a product?
ex. I would like to create a custom field for ‘product description’. Then I would like that custom field to be in a ‘product description tab underneath my product. I would also like to hide that tab if there is no information in the custom field.
I was able to accomplish this with the Advanced Custom Fields plug-in. But the plug-in will not let me import csv data into my custom fields. But if you add data into the advance custom field manually, the data shows up on a tab on the product page.
Here is the code I used for the advanced custom field:
‘add_filter( ‘woocommerce_product_tabs’, ‘my_theme_product_tabs’ );function my_theme_product_tabs( $tabs ) {
// ensure ACF is available
if ( !function_exists( ‘get_field’ ) )
return;$content = trim( get_field( ‘product_description’ ) );
if ( !empty( $content ) ) {
$tabs[] = array(
‘title’ => ‘Product Description’,
‘priority’ => 15,
‘callback’ => ‘my_theme_product_description’
);}
$content = trim( get_field( ‘product_features’ ) );
if ( !empty( $content ) ) {
$tabs[] = array(
‘title’ => ‘Product Features’,
‘priority’ => 20,
‘callback’ => ‘my_theme_product_features’
);}
$content = trim( get_field( ‘product_specifications’ ) );
if ( !empty( $content ) ) {
$tabs[] = array(
‘title’ => ‘Product Specifications’,
‘priority’ => 25,
‘callback’ => ‘my_theme_product_specifications’
);}
return $tabs;
}function my_theme_product_description() {
echo get_field( ‘product_description’ );
}function my_theme_product_features() {
echo get_field( ‘product_features’ );
}function my_theme_product_specifications() {
echo get_field( ‘product_specifications’ );
}’Any lead way would be amazing! I am desperate!
Thanks!
- The topic ‘Insert Custom Field into Custom Tab’ is closed to new replies.