Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Created December 12, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/2964fe197e21ef1a3d57958d89abcfb9 to your computer and use it in GitHub Desktop.
Save JudeRosario/2964fe197e21ef1a3d57958d89abcfb9 to your computer and use it in GitHub Desktop.
Update Manage Stock - Grouped products
/**
* Performs check before saving/inserting products
*/
function grouped_product_check($post_id, $post_data) {
// If this is just a revision, don't do anything.
if (wp_is_post_revision($post_id))
return;
if ($post_data['post_type'] == 'product') {
if( $post_data['post_parent'] != 0 ) {
update_post_meta($post_id, '_manage_stock', 'yes');
}
}
}
add_action( 'pre_post_update', 'grouped_product_check', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment