根据 WooCommerce 管理员中的产品类型显示或隐藏产品自定义字段

问题描述 投票:0回答:1

我向产品添加了自定义字段

add_action( 'woocommerce_product_options_sku', 'prodcode_fields');

function prodcode_fields() {
    global $post, $thepostid, $product_object;

    echo '<div class="options_prodcode_fields">';
   
    woocommerce_wp_text_input(
        array(
            'id' => '_prodcode_good_number',
            'value' => $product_object->get_meta('_prodcode_number', true),
        'type' => 'number',
            'label' => 'Product Code',
            'desc_tip' => true,
        'description' => __('Product Code', 'sv-prodcode'),
        )  );

echo '</div>';
}

一切都好,但有必要不要将其展示在可变商品中。您能告诉我如何使用 woocommerce 工具来做到这一点吗?

我尝试添加

'class' => 'show_if_simple',
,但我得到了废话 - 只有输入被隐藏,但标签等仍然保留。

php wordpress woocommerce product admin
1个回答
0
投票

要隐藏其他产品自定义字段,您可以使用 2 种方法:

wrapper_class
属性与“show_if_simple”或“hide_if_variable”一起使用,例如:

  • 'wrapper_class' => 'show_if_simple'
    ,
  • 'wrapper_class' => 'hide_if_variable'
    ,

或者您可以直接在开头使用“show_if_simple”或“hide_if_variable”

<div>
,例如:

echo '<div class="options_prodcode_fields show_if_simple">';

echo '<div class="options_prodcode_fields hide_if_variable">';
© www.soinside.com 2019 - 2024. All rights reserved.