Wordpress 致命错误:类';WC#U设置页面';使用命名空间时找不到

Wordpress 致命错误:类';WC#U设置页面';使用命名空间时找不到,wordpress,woocommerce,hook-woocommerce,Wordpress,Woocommerce,Hook Woocommerce,我在扩展WC\u设置页面时遇到了奇怪的问题。我想用它来添加设置选项卡(以及设置部分中的一些部分) 我的插件基于OOP,我的所有文件都有相关的名称空间。我有一个核心类,如下所示(如果您需要查看完整的结构,可以在我的repo中找到它: 因此,当我运行插件并调用init\u core()方法时,我遇到了以下错误: 致命错误:在第29行的…\wp content\plugins\siawood products\includes\admin\Class-WC-siawood-setting-tab1.p

我在扩展WC\u设置页面时遇到了奇怪的问题。我想用它来添加设置选项卡(以及设置部分中的一些部分)

我的插件基于OOP,我的所有文件都有相关的名称空间。我有一个核心类,如下所示(如果您需要查看完整的结构,可以在我的repo中找到它:

因此,当我运行插件并调用
init\u core()
方法时,我遇到了以下错误:

致命错误:在第29行的…\wp content\plugins\siawood products\includes\admin\Class-WC-siawood-setting-tab1.php中找不到类“WC\u Settings\u Page”

这很奇怪,因为我把它挂在woocommerce_加载或插件加载上,直到它能够在加载woocommerce后加载,但它不工作


如何解决此问题?

我将执行以下操作,而不是在加载的
插件上初始化类:

    public function init_core() {
        add_filter( 'woocommerce_get_settings_pages', [ $this, 'add_setting_page' ] );
    }

    public function add_setting_page( $settings ) {
        $settings[] = include_once path_to_your_file .  '/class-wc-siawood_setting_tab1 .php'
        return $settings;
    }
完整性:

    use Siawood_Products\Includes\Admin\WC_Siawood_Setting_Tab1;
    class Core implements Action_Hook_Interface, Filter_Hook_Interface {
    /*constructor of class and other things is here.....*/

        public function init_core() {
                add_action( 'woocommerce_get_settings_pages', [ $this, 'add_setting_page' ] );
        }

        public function add_setting_page(  ) {
            $settings[] = include_once $path_to_your_file .  '/class-wc-siawood_setting_tab1 .php'
            return $settings;
        }

    }
在另一个类文件中,该类必须初始化自身

    namespace Siawood_Products\Includes\Admin;

    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }

    class WC_Siawood_Setting_Tab1 extends \WC_Settings_Page {


        /**
         * Constructor.
         *
         * @version 1.3.0
         * @since   1.0.0
         */
        function __construct() {
            $this->id    = 'my_settings';
            $this->label = __( 'my label', 'my-textdomain-woocommerce' );
            parent::__construct();

        }
    }

    return new WC_Siawood_Setting_Tab1();

我不会在加载的插件上初始化类,而是执行以下操作:

    public function init_core() {
        add_filter( 'woocommerce_get_settings_pages', [ $this, 'add_setting_page' ] );
    }

    public function add_setting_page( $settings ) {
        $settings[] = include_once path_to_your_file .  '/class-wc-siawood_setting_tab1 .php'
        return $settings;
    }
完整性:

    use Siawood_Products\Includes\Admin\WC_Siawood_Setting_Tab1;
    class Core implements Action_Hook_Interface, Filter_Hook_Interface {
    /*constructor of class and other things is here.....*/

        public function init_core() {
                add_action( 'woocommerce_get_settings_pages', [ $this, 'add_setting_page' ] );
        }

        public function add_setting_page(  ) {
            $settings[] = include_once $path_to_your_file .  '/class-wc-siawood_setting_tab1 .php'
            return $settings;
        }

    }
在另一个类文件中,该类必须初始化自身

    namespace Siawood_Products\Includes\Admin;

    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }

    class WC_Siawood_Setting_Tab1 extends \WC_Settings_Page {


        /**
         * Constructor.
         *
         * @version 1.3.0
         * @since   1.0.0
         */
        function __construct() {
            $this->id    = 'my_settings';
            $this->label = __( 'my label', 'my-textdomain-woocommerce' );
            parent::__construct();

        }
    }

    return new WC_Siawood_Setting_Tab1();

非常感谢您的帮助。它工作正常。只需要在其文件中初始化类。非常感谢您的帮助。它工作正常。只需要在其文件中初始化类。非常感谢您