Last active
May 27, 2022 19:06
-
-
Save lewiswalsh/4f18012dfa694f1829e544046f5d4b67 to your computer and use it in GitHub Desktop.
Do something when a woocommerce product is updated #php #wordpress
This file contains 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
<?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