Saltar navegación

[Resuelto] Display Custom Field in Woocommerce Additional Tab

This support ticket is created hace 5 años. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Etiquetado: 

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel hace 5 años.

Asistido por: Nigel.

Autor
Mensajes
#1413353

I use this snippet for displaying new tab.

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'Anwendung', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;

}

function woo_new_product_tab_content() {
// The new tab content
echo '<h2>Anwendung</h2>';
echo (get_post_meta( $post->ID, "anwendung", true ));
}

And create Custom Field with "anwendung" slug.

But on frontend the Display of Field is missing.
But this snipped should work i guess?

There u see it:
enlace oculto

Edit:
I added this in the content function before echo … :
global $post;

Now it works. The solution is right?

#1413375

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

There is no $post variable declared in your second function.

You likely need the global $post object:

function woo_new_product_tab_content()
{
// The new tab content
    echo '<h2>Anwendung</h2>';
    global $post;
    echo (get_post_meta($post->ID, "anwendung", false));
}