要隐藏其他产品自定义域,您可以使用两种方法:
将wrapper_class
attribute与"show_if_Simple"或"Hide_IF_Variable"一起使用,如:
'wrapper_class' => 'show_if_simple'
,
'wrapper_class' => 'hide_if_variable'
,
也可以直接在开头的<div>
中使用show_if_Simple或Hide_IF_Variable,如:
echo '<div class="options_prodcode_fields show_if_simple">';
或
echo '<div class="options_prodcode_fields hide_if_variable">';
So in f或 your code:
add_action( 'woocommerce_product_options_sku', 'display_admin_product_custom_setting_fields');
function display_admin_product_custom_setting_fields() {
global $product_object;
// Only f或 simple product type
echo '<div class="options_prodcode_fields show_if_simple">';
woocommerce_wp_text_input(
array(
'id' => '_prodcode_good_number',
'type' => 'number',
'label' => __('Product Code', 'sv-prodcode'),
'description' => __('Product code description', 'sv-prodcode'),
'desc_tip' => true,
'value' => $product_object->get_meta('_prodcode_number'),
) );
echo '</div>';
}
Addition
The different product type classes to show 或 hide a custom product field
By Default in WooCommerce:
- Product type "simple":
show_if_simple
或 hide_if_simple
- Product type "variable":
show_if_variable
或 hide_if_variable
- Product type "external":
show_if_external
或 hide_if_external
- Product type "grouped":
show_if_grouped
或 hide_if_grouped
- Virtual product:
show_if_virtual
或 hide_if_virtual
- Downloadable product:
show_if_downloadable
或 hide_if_downloadable
Some other f或eign products:
- Product type "subscription":
show_if_subscription
或 hide_if_subscription
- Product type "booking":
show_if_booking
或 hide_if_booking
- Product type "bundle":
show_if_bundle
或 hide_if_bundle