I need to change product post_status in a hook. I trying to make product get back to "pending" status everytime vendor change the price.
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 == '_price' ) { // edited price
if ( get_post_type( $post_id ) == 'product' ) {
$product = wc_get_product( $post_id );
$product['post_status'] = 'pending'; //how to update this?
// var_dump($product_id);var_dump($product);die('test');
}
}
}
Can someone tell me what function could do this: "$product['post_status'] ='pending';"?
The following code will change the product status to pending if anyone else than the "administrator" user role update product prices in backend:
Code goes in function.php file of your active child theme (or active theme). Tested and works.