0

Im coding a tab for woocommerce that shows on specific products (kimonos). the code I have sucessfully shows the tab on the kimono product page, but gives a critical error for non kimono items.

function FAQ_kim( $tabs ) {
    
    global $product;
    if ( ! $product ) {
        return;
    }

    $product_id = $product->get_id();
    if ( ! has_term( 'kimonos-and-gowns', 'product_cat', $product_id ) ) {
        return;
    }
    
    $tabs['FAQ'] = array(
        
        'title'  =>  'FAQ',
        
        'priority' => 40,
        
        'callback' => 'faq_content');
    
    return $tabs;
}

function faq_content() { echo 'test';}

add_filter( 'woocommerce_product_tabs', 'FAQ_kim' );

when i debug the code it tells me that:

PHP Fatal error:  Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /var/www/html/wp-content/themes/goldish/includes/woocommerce/woocommerce.php:1374

How do i get around this, and not have the tab display on non kimono products?

Thanks

Tomtom
  • 90
  • 4
  • At certain points you return nothing, while this should be an array (`$tabs`). So `return;` must be replaced (2x) with `return $tabs;` – 7uc1f3r Nov 03 '22 at 11:39

0 Answers0