• I’m trying to add a custom tab to the Product Data meta box that will simply list some of the product’s information so it can be printed.

    I have the tab showing, and I have some of the information showing. The problem is that it shows on either ALL the tabs or NONE of the tabs.

    This is the code:

    add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' , 99 , 1 );
        function add_my_custom_product_data_tab( $product_data_tabs ) {
        $product_data_tabs['my-custom-tab'] = array(
            'label' => __( 'Print Me', 'my_text_domain' ),
            'target' => 'my_custom_product_data',
    	  	'callback' 	=> 'add_my_custom_product_data_fields'
        );
        return $product_data_tabs;
        }
    
        add_action( 'woocommerce_product_data_panels', 'add_my_custom_product_data_fields' );
        function add_my_custom_product_data_fields() {
        global $post;
    
        $product_sku = get_post_meta( $post->ID, '_sku', true );
        echo '  SKU:  '.$product_sku;
      
          echo '<br><br>';
      
    	$product_title = get_post_meta( $post->ID, 'post_title', true );
        echo '&nbsp;&nbsp;Title:&nbsp; '.$product_title;
        }

    The main problem is that it’s not only showing up on the “Print Me” custom tab, it’s showing up at the bottom of ALL the tabs in the Product Data meta box.

    I know I’m probably missing something simple, but I just can’t see it.

    • This topic was modified 7 years, 9 months ago by mugwumpr. Reason: Fix code weirdness
  • The topic ‘Display product info on custom product data tab in admin’ is closed to new replies.