Created
May 10, 2018 16:06
-
-
Save robertdevore/e57b2f2d6fb8bce46558d672618db7dd to your computer and use it in GitHub Desktop.
Do something when a product is published in WooCommerce
This file contains hidden or 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 | |
| /** | |
| * @snippet Do Something When Product is Published | |
| * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 | |
| * @sourcecode https://businessbloomer.com/?p=543 | |
| * @author Rodolfo Melogli | |
| * @testedwith WooCommerce 3.2.6 | |
| */ | |
| function add_this_to_new_products( $new_status, $old_status, $post ) { | |
| global $post; | |
| if ( $post->post_type !== 'product' ) return; | |
| if ( 'publish' !== $new_status or 'publish' === $old_status ) return; | |
| add_post_meta( $post->ID, 'total_amount', '0', true ); // This is the action to take | |
| } | |
| add_action( 'transition_post_status', 'add_this_to_new_products', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment