Skip to content

Instantly share code, notes, and snippets.

@iyut
Created March 15, 2021 13:14
Show Gist options
  • Save iyut/35b97134298f9c43d293023cad323202 to your computer and use it in GitHub Desktop.
Save iyut/35b97134298f9c43d293023cad323202 to your computer and use it in GitHub Desktop.
Hook after product is created or updated
add_action( 'save_post', 'product_created_or_updated', 10, 3);
function product_created_or_updated($post_id, $post, $update){
if ($post->post_status != 'publish' || $post->post_type != 'product') {
return;
}
if ( !$product = wc_get_product( $post_id ) ) {
return;
}
// Make something with $product
// You can also check $update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment