Created
December 12, 2020 14:55
-
-
Save JudeRosario/2964fe197e21ef1a3d57958d89abcfb9 to your computer and use it in GitHub Desktop.
Update Manage Stock - Grouped products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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