Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 WooCommerce自定义产品类型选项不隐藏自定义产品选项卡_Php_Jquery_Wordpress_Woocommerce_Product - Fatal编程技术网

Php WooCommerce自定义产品类型选项不隐藏自定义产品选项卡

Php WooCommerce自定义产品类型选项不隐藏自定义产品选项卡,php,jquery,wordpress,woocommerce,product,Php,Jquery,Wordpress,Woocommerce,Product,我刚刚在我的WC管理产品页面中添加了一个自定义产品类型选项: 我还添加了一个自定义产品数据选项卡,我只想在选中该选项时显示该选项卡: add_filter( 'woocommerce_product_data_tabs', [ $this, 'filter_woocommerce_product_data_tabs' ] ); public function filter_woocommerce_product_data_tabs( array $tabs ): array { $ta

我刚刚在我的WC管理产品页面中添加了一个自定义产品类型选项:

我还添加了一个自定义产品数据选项卡,我只想在选中该选项时显示该选项卡:

add_filter( 'woocommerce_product_data_tabs', [ $this, 'filter_woocommerce_product_data_tabs' ] );
public function filter_woocommerce_product_data_tabs( array $tabs ): array {
    $tabs['woo_batches'] = [
        'label'    => esc_html__( 'Batches', 'woo-batches' ),
        'target'   => 'woo_batches',
        'class'    => [ 'show_if_simple', 'show_if_variable', 'show_if_batches' ],
        'priority' => 25
    ];

    return $tabs;
}
但是,当我选中/取消选中我的选项时,该选项卡完全不起任何作用。我需要我自己的隐藏JS函数,还是我遗漏了什么?我通常认为我可以用它来显示/隐藏一切

show_if_xxx
hide_if_xxx

您必须自己提供jQuery的一部分。如何将其应用于其他复选框(默认值),请参见(第122行…)

注意:我还对您现有的代码做了一些小改动,其中包括某些类

所以你得到:

//添加一个复选框作为电子商务管理产品选项
函数过滤器产品类型选项($product类型选项){
$product_type_options['batches']=数组(
“id'=>“\u批次”,
'wrapper\u class'=>'show\u if\u simple show\u if\u variable',
'label'=>\('Batches','woo Batches'),
'description'=>uuuu('products is sall from batches','woo batches'),
“默认值”=>“否”,
);
返回$product\类型\选项;
}
添加过滤器(“产品类型选项”、“过滤器产品类型选项”,10,1);
//添加自定义产品设置选项卡。
功能过滤器\商业\产品\数据\选项卡($默认\选项卡){
$default_tabs['woo_batches']=数组(
'label'=>\('Batches','woo Batches'),
“目标”=>“woo_批次”,
'class'=>数组('hide_if_simple'、'hide_if_variable'、'show_if_batches'),
“优先级”=>25
);
返回$default_选项卡;
}
添加过滤器('woocommerce\产品\数据\选项卡','filter\ woocommerce\产品\数据\选项卡',10,1);
//打印默认页脚脚本之前的脚本或数据。
//这个钩子仅供管理员使用,不能用于在前端添加任何内容。
函数操作\管理\页脚(){
?>
jQuery(文档).ready(函数($){
$('input#(u批处理')。更改(函数(){
变量为_批次=$('input#_批次:checked')。长度;
//显示规则。
if(is_批次){
$('.show_if_batches').show();
}
});            
});
show_if_xxx
hide_if_xxx