Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Adding multiple tabs for specific products to WooCommerce single product pages

I'm trying to show extra product tabs on specific products using $post_id I'm not sure if it's done it right? this way works for other small snippets i've wrote.

The product tabs work if i have them display on all product, but i want to limit some to specific products.

My code attempt:

add_filter( 'woocommerce_product_tabs', 'artwork_product_tab' );
function artwork_product_tab( $tabs, $post_id ) {
    if( in_array( $post_id, array( 8125 ) ) ){
// Adds the new tab
return $tabs['artwork_guidelines'] = array(
        'title'     => __( 'Artwork Guidelines', 'woocommerce' ),
        'priority'  => 50,
        'callback'  => 'artwork_product_tab_content'
    );
    }
        $tabs['standard_sizes'] = array(
        'title'     => __( 'Standard Sizes', 'woocommerce' ),
        'priority'  => 60,
        'callback'  => 'standard_sizes_product_tab_content'
    );
return $tabs;
}

Any help is appreciated!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

$post_id is not passed to the woocommerce_product_tabs filter hook.

You can use global $product & $product->get_id() instead.

So you get:

function filter_woocommerce_product_tabs( $tabs ) {
    global $product;
    
    // Is a WC product
    if ( is_a( $product, 'WC_Product' ) ) {
        // Get product ID
        $product_id = $product->get_id();
    
        // Compare
        if ( in_array( $product_id, array( 8125, 30, 815 ) ) ) {
        
            $tabs['artwork_guidelines'] = array(
                'title'     => __( 'Artwork Guidelines', 'woocommerce' ),
                'priority'  => 50,
                'callback'  => 'artwork_product_tab_content'
            );
            
            $tabs['standard_sizes'] = array(
                'title'     => __( 'Standard Sizes', 'woocommerce' ),
                'priority'  => 60,
                'callback'  => 'standard_sizes_product_tab_content'
            );
        }
    }
    
    return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'filter_woocommerce_product_tabs', 100, 1 );

// New Tab contents
function artwork_product_tab_content() {
    echo '<p>artwork_product_tab_content</p>';
}
function standard_sizes_product_tab_content() {
    echo '<p>standard_sizes_product_tab_content</p>';
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!