让 Woocommerce 默认管理库存 [英] Get Woocommerce to Manage Stock as a default

查看:29
本文介绍了让 Woocommerce 默认管理库存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个钩子可以允许在全局的 woocommerce 中设置库存 > 管理库存复选框?

我所有的产品都是单件数量,所以总是要记得检查它似乎很反D.R.Y,特别是对于其他员工.

All my products are single item quantity, so it seems pretty counter-D.R.Y to always have to remember to check it, especially for other employees.

推荐答案

有点晚了,但这里是其他需要这样做的人的方法...我在其他地方找到了大部分代码,但我没有再链接到我找到它的地方.稍微调整一下,这就是我最终得到的(添加到 functions.php):

A little late, but here's how for anyone else needing to do this... I found most of this code somewhere else, but I don't have the link anymore to where I found it. Tweaked it a little and this is what I ended up with (add to functions.php):

add_action( 'admin_enqueue_scripts', 'wc_default_variation_stock_quantity' );
function wc_default_variation_stock_quantity() {
  global $pagenow, $woocommerce;

  $default_stock_quantity = 1;
  $screen = get_current_screen();

  if ( ( $pagenow == 'post-new.php' || $pagenow == 'post.php' || $pagenow == 'edit.php' ) && $screen->post_type == 'product' ) {

    ?>
<!-- uncomment this if jquery if it hasn't been included
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
-->
    <script type="text/javascript">
    jQuery(document).ready(function(){
        if ( !jQuery( '#_manage_stock' ).attr('checked') ) {
          jQuery( '#_manage_stock' ).attr('checked', 'checked');
        }
        if ( '' === jQuery( '#_stock' ).val() ) {
          jQuery( '#_stock' ).val(<?php echo $default_stock_quantity; ?>);
        }
    });
    </script>
    <?php
  }
}

这篇关于让 Woocommerce 默认管理库存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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