如何检测新的安装或卸载woocommerce插件? 我在他们的文档中找不到任何参考。
答案 0 :(得分:0)
是的,插件激活和停用时会触发两个操作。这两项操作是activated_plugin
和deactivated_plugin
您可以像这样使用它们
function detect_plugin_activation( $plugin, $network_activation ) {
if( $plugin == "woocommerce/woocommerce.php" ) {
// Woocommerce activated
// Do your stuff here
}
}
add_action( 'activated_plugin', 'detect_plugin_activation', 10, 2 );
function detect_plugin_deactivation( $plugin, $network_activation ) {
if( $plugin == "woocommerce/woocommerce.php" ) {
// Woocommerce deactivated
// Do your stuff here
}
}
add_action( 'deactivated_plugin', 'detect_plugin_deactivation', 10, 2 );
激活时,woocommerce本身会再触发一个动作
function on_woocommerce_installed() {
// This action triggered exclusivly by woocommerce at the time of activation
}
add_action( 'woocommerce_installed', 'on_woocommerce_installed' );