默认情况下为 WooCommerce 中的特定产品类型自动启用虚拟选项

我有名为“预订”的 Woocommerce 产品类型,我想做的是在创建时自动将其标记为“虚拟”。


基于“自动启用虚拟和可下载产品设置”答案代码,下面的代码将所有产品设置为虚拟,而我只希望“预订”产品类型默认为虚拟,而不是简单或可变的产品:


add_action( 'woocommerce_product_options_general_product_data', 'enable_virtual_option' );

function enable_virtual_option(){


?>


        <script>

            (function($){

                $('input[name=_virtual]').prop('checked', true);


            })(jQuery);

        </script>


        <?php


}


皈依舞
浏览 168回答 1
1回答

PIPIONE

以下将自动启用特定产品类型的虚拟复选框(此处为“预订”类型):add_action( 'woocommerce_product_options_general_product_data', 'hiding_and_set_product_settings' );function hiding_and_set_product_settings(){&nbsp; &nbsp; global $post, $product_object;&nbsp; &nbsp; if ( $product_object->is_type('booking') ){&nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (function($){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('input[name=_virtual]').prop('checked', true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })(jQuery);&nbsp; &nbsp; &nbsp; &nbsp; </script>&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; }}代码位于活动子主题(或活动主题)的 function.php 文件中。测试和工作。
打开App,查看更多内容
随时随地看视频慕课网APP