要设置新帖子的默认值,可以尝试以下代码:
$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);