在woocommerce中添加股票期权
我想在产品的股票期权下拉列表中添加一个新选项。默认情况下,有缺货,有库存,我想添加第三个选项。
I would like to add a new option to the dropdown list of stocks options for a product. By default, there is "Out of stock", "In stock" and I would like to add a third option.
我发现了显示下拉菜单的方法class-wc-meta-box-product-data.php)
I found the method that displays the dropdown ( in class-wc-meta-box-product-data.php )
// Stock status
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' )
), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
do_action( 'woocommerce_product_options_stock_status' );
但是我不想直接编辑Woocommerce类,所以我们可以更新Woocommerce,自定义代码。有没有办法重写这个方法?
But I don't want to edit Woocommerce class directly, so that we can update Woocommerce without losing any custom code. Is there a way to override this method ?
好吧,我最后隐藏了Javascript中的前股票期权下拉菜单
Well, I ended up hiding the former stock option dropdown in Javascript
add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');
function add_custom_stock_type() {
// Stock status - We remove the default one
?>
<script type="text/javascript">
jQuery('_stock_status').remove();
</script>
<?php
}
: http://www.remicorson.com/mastering-woocommerce-products-custom -fields /
不确定这是最干净的解决方案,但它不至少触及核心文件! :)
and created a new one using this tutorial: http://www.remicorson.com/mastering-woocommerce-products-custom-fields/ Not sure it's the cleanest solution but it doesn't touch the core files at least ! :)