Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对于每个循环(数组)隐藏自定义选项卡_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 对于每个循环(数组)隐藏自定义选项卡

Php 对于每个循环(数组)隐藏自定义选项卡,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,大家好,我一直在努力隐藏我的woocommerce产品页面中的自定义选项卡,这取决于分组产品子产品是否包含某个属性。我的代码看起来不错,但问题是当我在functions.php文件中使用它时,产品页面上的所有选项卡都会消失。这是我的密码 add_filter( 'woocommerce_product_tabs', 'woo_simfree_product_tab' ); function woo_simfree_product_tab( $tabs ) { global $post; if

大家好,我一直在努力隐藏我的woocommerce产品页面中的自定义选项卡,这取决于分组产品子产品是否包含某个属性。我的代码看起来不错,但问题是当我在functions.php文件中使用它时,产品页面上的所有选项卡都会消失。这是我的密码

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;
        }

}
}
有人能看到任何问题或给我指出正确的方向吗?谢谢

更新:现在显示产品选项卡,因为如果$PAYG=true,我忘记返回$tabs,但由于某些原因,该函数无法工作。该选项卡仍显示在产品页面上,但不应显示在该页面上。有人知道为什么吗

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;
        }

}
}
更新:我现在已经能够使标签完全空,如果没有产品,有反正隐藏自定义标签,如果空

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;
}
}

}  

$PAYG出于某种原因必须始终为真$PAYG出于某种原因必须始终为真