admin管理员组文章数量:1425717
There is some hook that is triggered after WooCommerce Install (I mean the WooCommerce Wizard, not the plugin installation)? I didn't found a hook to do this and the Wizard Class (WC_Admin_Setup_Wizard) didn't have much hooks to achieve that. Any ideas?
The problem I'm trying to solve is that WooCommerce is setting fresh_site option to 0 (I believe is because the posts it creates in installation process). So I want reset it to 1 after installation and setup my theme. Thanks!
There is some hook that is triggered after WooCommerce Install (I mean the WooCommerce Wizard, not the plugin installation)? I didn't found a hook to do this and the Wizard Class (WC_Admin_Setup_Wizard) didn't have much hooks to achieve that. Any ideas?
The problem I'm trying to solve is that WooCommerce is setting fresh_site option to 0 (I believe is because the posts it creates in installation process). So I want reset it to 1 after installation and setup my theme. Thanks!
Share Improve this question edited Jun 18, 2019 at 12:59 Lucas Vendramini asked Jun 18, 2019 at 12:44 Lucas VendraminiLucas Vendramini 3032 silver badges11 bronze badges1 Answer
Reset to default 1WooCommerce 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.
本文标签: pluginsWooCommerce after install hook
版权声明:本文标题:plugins - WooCommerce: after install hook 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745391205a2656605.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论