小编Pod*_*eEu的帖子

为什么 add_action 仅适用于 functions.php 而不是插件?

当我把我的代码 functions.php

从...开始

add_action( 'woocommerce_order_status_completed', 'do_something' );
here is my code
Run Code Online (Sandbox Code Playgroud)

有用!但是当我把它放进去plugin

if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

    if ( ! class_exists( 'WC_Some_class' ) ) {

    class  WC_Some_class {
            public function __construct() {
            add_action( 'woocommerce_order_status_completed', 'do_something' );
}
script ...

}
}
// finally instantiate our plugin class and add it to the set of globals
        $WC_Some_class = new WC_Some_class();
    }
}
Run Code Online (Sandbox Code Playgroud)

这不起作用。为什么?

php wordpress plugins woocommerce

2
推荐指数
1
解决办法
7806
查看次数

标签 统计

php ×1

plugins ×1

woocommerce ×1

wordpress ×1