Support

Account

Home Forums Backend Issues (wp-admin) Snippet for Custom Field to Display in Product Tab Reply To: Snippet for Custom Field to Display in Product Tab

  • Hi James
    In this case, how shall we hide that tab or remove that tab if get_field('fieldname', $post_id); is empty.

    Sorry to bother you, I found the solution:

    //adding new tab//
    add_filter( 'woocommerce_product_tabs', 'product_tab' );
    function product_tab( $tabs ) {
    if ( get_field('fieldname', $post_id) ) {
    $tabs[] = array(
    'title' => 'Specifications',
    'priority' => 15,
    'callback' => 'show_content'
    );
    }
    return $tabs;
    }
    function show_content() {
    $downloads = get_field('fieldname', $post_id);
    if( $downloads ):
    echo get_field('fieldname', $post_id);
    endif;
    }