In WooCommerce, I’m trying to trigger an action when a product is published, but it doesn’t work, here is my code:
add_action( 'transition_post_status', 'my_call_back_function', 10, 3 );
function my_call_back_function( $new_status, $old_status, $post ) {
if (
'product' !== $post->post_type ||
'publish' !== $new_status ||
'publish' === $old_status
) {
return;
}
file_put_contents( 'file.txt', 'Product published', FILE_APPEND );
}
Here I’m trying to create a file and put some text in it. But as I said, the file isn’t created.
I’m using wordpress 5.8.1 and Woocommerce 5.8.0. What is the problem and how to solve it? Your help would be greatly appreciated.
Thanks in advance.