我们有一个特殊的WooCommerce设置,每个产品只卖一次。因此,我们将每个产品设置为在自动创建时有一个库存。
使用WooCommerce中的库存管理功能需要一个选项:“启用产品级的库存管理”,并使用复选框“选中”
在产品创建时,是否有一个函数或任何东西可以使此框“自动选中”?
谢谢你的帮助!
发布于 2018-01-24 12:12:48
若要设置新帖子的默认值,可以尝试以下代码:
$postType = "product";
add_action("save_post_" . $postType, function ($post_ID, \WP_Post $post, $update) {
if (!$update) {
// default values for new products
update_post_meta($post->ID, "_manage_stock", "yes");
update_post_meta($post->ID, "_stock", 1);
return;
}
// here, operations for updated products
}, 10, 3);https://wordpress.stackexchange.com/questions/291992
复制相似问题