我刚刚向我的 WC 管理产品页面添加了自定义产品类型选项:
add_filter( 'product_type_options', [ $this, 'filter_product_type_options' ], 99, 1 );
public function filter_product_type_options( array $product_type_options ): array {
$product_type_options['batches'] = [
'id' => '_batches',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => esc_html__( 'Batches', 'woo-batches' ),
'description' => esc_html__( 'Product is sold from batches.', 'woo-batches' ),
'default' => 'no',
];
return $product_type_options;
}
我还添加了一个自定义产品数据选项卡,我只想在选中该选项时显示该选项卡:
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