Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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,我设置了一些自定义选项卡以显示分组产品 add_filter( 'woocommerce_product_tabs', 'woo_paym_product_tab' ); function woo_paym_product_tab( $tabs ) { global $post; if( function_exists('get_product') ){ $product = get_product( $post->ID ); if( $p

我设置了一些自定义选项卡以显示分组产品

add_filter( 'woocommerce_product_tabs', 'woo_paym_product_tab' );

function woo_paym_product_tab( $tabs ) {
    global $post;
    if( function_exists('get_product') ){
        $product = get_product( $post->ID );
        if( $product->is_type( 'grouped' ) ){
            $tabs['paym-plans'] = array( 'title' => __( 'Contract Deals', 'woocommerce' ), 'priority' => 10, 'callback' => 'woo_paym_product_tab_content' );
            return $tabs;
        } else {
        return $tabs;
        }
    }
}

function woo_paym_product_tab_content() {
    // The new tab content
    woocommerce_template_single_add_to_cart();
} 
如何根据分组产品>子产品属性隐藏此选项卡。如果子产品包含属性“PAYM”,我只希望此选项卡显示在分组产品页面上


目前,该选项卡设置为仅显示“分组”产品。我还想将其更改为“分组”产品和特定类别。

以下功能将帮助您隐藏其他产品类型的选项卡

// Show custom fields for grouped product.

function hide_custom_js() {

if ( 'product' != get_post_type() ) :
    return;
endif;

?><script type='text/javascript'>
    jQuery( document ).ready( function() {
        jQuery( '.your_custom _tab_class' ).addClass( 'show_if_grouped' ).show();
    });
</script><?php
}
add_action( 'admin_footer', 'hide_custom_js' );
//显示分组产品的自定义字段。
函数hide_custom_js(){
如果('product'!=get_post_type()):
返回;
endif;
?>
jQuery(文档).ready(函数(){
jQuery('.your_custom_tab_class').addClass('show_if_grouped').show();
});

对于第二位,这是否有效?
如果($product->is_type('grouped')&&$product->is_category('your_category'))
,实际上,对于第一位,您应该能够只测试
$product->get_attribute('PAYM');
,但我已经很久没有使用wooCommerce了,所以我没有信心将其作为answer@JohnCH (回复第一条评论)当我尝试不显示任何标签,甚至连它破坏网站的页脚都不显示时,这是行不通的???@JohnCH(回复第二条评论)该属性仅在子产品中可见。PAYM仅适用于组的子产品,而不适用于组本身。虽然我不能100%确定它是否也会获取子产品的属性,但您认为如何?我不知道第一个,它是否会给您一条错误消息?对于第二个,您可能需要执行
$product->get_children()
然后对子对象使用
get_属性('PAYM')