Sauter la navigation

[Résolu] Display Custom Field in Woocommerce Additional Tab

This support ticket is created Il y a 5 années et 1 mois. 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)

Marqué : 

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Nigel Il y a 5 années et 1 mois.

Assisté par: Nigel.

Auteur
Publications
#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:
lien caché

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

Now it works. The solution is right?

#1413375

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: 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));
}