WooCommerce “product published” action

/**
 * Fires WooCommerce "product published" (`wpcodebook_product_published`) action.
 *
 * @see https://wpcodebook.com/woocommerce-product-published-action/
 * @see https://developer.wordpress.org/reference/hooks/transition_post_status/
 */
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
	if (
		'product' === $post->post_type &&
		'publish' === $new_status &&
		'publish' !== $old_status
	) {
		do_action( 'wpcodebook_product_published', $post->ID );
	}
}, 10, 3 );

Leave a Comment