对于每个循环(WooCommerce Array)隐藏自定义选项卡

Hi guys I have been really trying hard to hide a custom tab in my woocommerce product page depending on weather the grouped products child product contains a certain attribute. My code looks good but the problem is when I use it in my functions.php file all tabs on my product pages disappear. Here's my code.

add_filter( 'woocommerce_product_tabs', 'woo_simfree_product_tab' );

function woo_simfree_product_tab( $tabs ) {

global $post;
if  (function_exists( 'get_product' )) {
    $product = get_product( $post->ID );

        if ($product->is_type( 'grouped' )) {
                $PAYG = false;

                foreach ($product->get_children() as $child_id) {
                    $child = get_product($child_id);
                    $attr = $child->get_attribute('contract-type');
                        if ($attr == 'PAYG') {
                            $PAYG = true;
                        }
                }

                if ($PAYG = true) {
                    $tabs['simfree-plans'] = array( 'title' => __( 'SIM Free', 'woocommerce' ), 'priority' => 20, 'callback' => 'woo_simfree_product_tab_content' );
                } else {
                    return $tabs;
                }

        } else {
            return $tabs;
        }

}
}

Can anyone see any problems or point me in the right direction thanks.

UPDATE: Now the product tabs are showing as I forgot to return $tabs if $PAYG = true, but the function is not working for some reason. The tab is still showing on the product pages it's not supposed to be showing on. Anyone know why?

add_filter( 'woocommerce_product_tabs', 'woo_simfree_product_tab' );

function woo_simfree_product_tab( $tabs ) {

global $post;
if  (function_exists( 'get_product' )) {
    $product = get_product( $post->ID );

        if ($product->is_type( 'grouped' )) {
                $PAYG = false;

                foreach ($product->get_children() as $child_id) {
                    $child = get_product($child_id);
                    $attr = $child->get_attribute('contract-type');
                        if ($attr == 'PAYG') {
                            $PAYG = true;
                        }
                }

                if ($PAYG = true) {
                    $tabs['simfree-plans'] = array( 'title' => __( 'SIM Free', 'woocommerce' ), 'priority' => 20, 'callback' => 'woo_simfree_product_tab_content' );
                    return $tabs;
                } else {
                    return $tabs;
                }

        } else {
            return $tabs;
        }

}
}

UPDATE: I have now been able to make the tab completely empty if no product is there is there anyway to hide woocommerce custom tab if empty.

add_filter( 'woocommerce_product_tabs', 'woo_simfree_product_tab' );

function woo_simfree_product_tab( $tabs ) {

global $post;
if( function_exists('get_product') ){
$product = get_product( $post->ID );
if( $product->is_type( 'grouped' ) ){
        $tabs['simfree-plans'] = array( 'title' => __( 'SIM Free', 'woocommerce' ), 'priority' => 20, 'callback' => 'woo_simfree_product_tab_content' );
    return $tabs;
} else {
    return $tabs;
}
}

}