简体   繁体   English

在 Woocommerce 中批量启用产品库存管理

[英]Bulk enable product stock management in Woocommerce

I have a WooCommerce shop with around 12,000 products and only about 10% have stock management enabled.我有一个 WooCommerce 商店,里面有大约 12,000 种产品,只有大约 10% 启用了库存管理。 I need to bulk enable stock management on all products.我需要对所有产品批量启用库存管理。

Does anyone have any ideas for the best way to accomplish this?有没有人对实现这一目标的最佳方法有任何想法?

Any help is appreciated.任何帮助表示赞赏。

To bulk enabling stock management for all products.批量启用所有产品的库存管理。 There is 2 ways:有2种方式:

1) PHP: Using the following code Will update the database with a very light SQL query: 1) PHP:使用以下代码将使用非常轻的 SQL 查询更新数据库:

function bulk_enable_product_stock_management(){
    // Only for administrator user role
    if( ! current_user_can( 'administrator' ) ) return;

    global $wpdb;

    $wpdb->query( "
        UPDATE {$wpdb->prefix}postmeta
        SET meta_value = 'yes'
        WHERE meta_key = '_manage_stock'
    " );
}

bulk_enable_product_stock_management();

Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。

USAGE Once saved, to run the code, browse any page of your web site as an administrator.用法保存后,要运行代码,请以管理员身份浏览网站的任何页面。 Then remove this code.然后删除此代码。


2) MySQL/SQL: With a direct SQL query using PhpMyAdmin: 2) MySQL/SQL:通过使用 PhpMyAdmin 的直接 SQL 查询:

UPDATE wp_postmeta
SET meta_value = 'yes'
WHERE meta_key = '_manage_stock'

Both ways will bulk enable product stock management两种方式都将批量启用产品库存管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM