Navigation überspringen

[Gelöst] Display Custom Field in Woocommerce Additional Tab

This support ticket is created vor 5 Jahren. 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)

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Nigel vor 5 Jahren.

Assistiert von: Nigel.

Author
Artikel
#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:
versteckter Link

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

Now it works. The solution is right?

#1413375

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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