WooCommerce 自定义产品类型库存选项卡中缺少单独销售字段

Sold Individually field missing in WooCommerce Custom Product type Inventory tab

如何在自定义产品类型 "Test Product" 中显示 "Sold Individually" 字段?

我尝试使用以下钩子函数

static function addField() {
    echo "<script>jQuery('.show_if_simple').addClass('show_if_test');
    jQuery('._sold_individually_field.show_if_simple').addClass('show_if_test');
    </script>";
    }
    add_action('woocommerce_product_options_general_product_data','addField'));

请在您的 function.php 文件中添加以下代码。您需要添加 class show_if_{your_custom_product_type} 在您的情况下它将是 show_if_test。将 show_if_simple_rental 替换为 show_if_{your_custom_product_type}。了解更多信息

function wh_simple_rental_admin_custom_js() {

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

    ?>
    <script type='text/javascript'>
        jQuery(document).ready(function () {
            //for Inventory tab
            jQuery('.inventory_options').addClass('show_if_simple_rental').show();

            jQuery('#inventory_product_data ._sold_individually_field').parent().addClass('show_if_simple_rental').show();
            jQuery('#inventory_product_data ._sold_individually_field').addClass('show_if_simple_rental').show();
        });
    </script>
    <?php

}

add_action('admin_footer', 'wh_simple_rental_admin_custom_js');