在woocommerce中添加股票期权 [英] Add stock option in woocommerce

查看:314
本文介绍了在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 ! :)

这篇关于在woocommerce中添加股票期权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆