WooCommerce itself isn't setting fresh_site
to 0
directly (the string fresh_site
doesn't appear anywhere in WooCommerce's source code), however you are correct that it's happening because WooCommerce is creating pages.
WordPress sets a site to not be fresh like this (from wp-includes/default-filters.php
):
// Mark site as no longer fresh
foreach ( array( 'publish_post', 'publish_page', 'wp_ajax_save-widget', 'wp_ajax_widgets-order', 'customize_save_after' ) as $action ) {
add_action( $action, '_delete_option_fresh_site', 0 );
}
So when WooCommerce creates its pages, publish_page
is fired and the site is no longer considered fresh.
Unfortunately there doesn't appear to be any hooks that fire specifically when the setup wizard is complete, when completing any steps in the wizard, or even when the default WooCommerce pages are created. I think I have figured out a workaround, though.
The entirety of the WooCommerce setup wizard takes place on an admin page, ?page=wc-setup
, which is output by WooCommerce using the admin_init
hook, at the default priority of 10
. So what we can do is hook into admin_init
at a higher priority (lower number), check if we're in the WooCommerce wizard, and if so, remove the hook that sets a site to not be fresh. This way nothing that happens during the setup wizard can make the site no longer fresh:
function wpse_340803_keep_setup_wizard_fresh() {
if ( isset( $_GET['page'] ) && 'wc-setup' === $_GET['page'] ) {
foreach ( array( 'publish_post', 'publish_page', 'wp_ajax_save-widget', 'wp_ajax_widgets-order', 'customize_save_after' ) as $action ) {
remove_action( $action, '_delete_option_fresh_site', 0 );
}
}
}
add_action( 'admin_init', 'wpse_340803_keep_setup_wizard_fresh', 0 );
Since the page creation is triggered inside admin_init
at priority 10
, as part of the setup wizard, the _delete_option_fresh_site
is no longer hooked to be fired when the pages are created, meaning that the site should still be fresh afterwards.