Skip to content

Instantly share code, notes, and snippets.

@lewiswalsh
Last active May 27, 2022 19:06
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 lewiswalsh/4f18012dfa694f1829e544046f5d4b67 to your computer and use it in GitHub Desktop.
Save lewiswalsh/4f18012dfa694f1829e544046f5d4b67 to your computer and use it in GitHub Desktop.
Do something when a woocommerce product is updated #php #wordpress
<?php
add_action( 'added_post_meta', 'mp_sync_on_product_save', 10, 4 );
add_action( 'updated_post_meta', 'mp_sync_on_product_save', 10, 4 );
function mp_sync_on_product_save( $meta_id, $post_id, $meta_key, $meta_value ) {
if ( $meta_key == '_edit_lock' ) { // we've been editing the post
if ( get_post_type( $post_id ) == 'product' ) { // we've been editing a product
$product = wc_get_product( $post_id );
// do something with this product
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment