Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Fatal error: Class ‘WC_Settings_Page’ not found when use namespace

$
0
0

Replies: 0

I have strange problem to extend WC_Settings_Page. I want to use it to add setting tab (and some sections inside it in Woocommerce setting sections.

My plugin is based on OOP and all of my files has related namespace. I have a core class which is something like this in the following (if you need to see the complete structure, you can find it in my github repo:


<?php
/**
 * The file that defines the core plugin class
 *
 * A class definition that includes attributes and functions used across both the
 * public-facing side of the site and the admin area.
 *
 * @package    Siawood_Products
 * @author     Mehdi Soltani Neshan <soltani.n.mehdi@gmail.com>
 * @license    https://www.gnu.org/licenses/gpl-3.0.txt GNU/GPLv3
 * @link       https://wpwebmaster.ir
 * @since      1.0.0
 */

namespace Siawood_Products\Includes\Init;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/* Some uses is hear */
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() {
			/* FYI: I checked before is woocommerce is active or not, if active, I call init_core() */
			add_action( 'plugins_loaded', [ $this, 'add_setting_page' ] );
	}

	public function add_setting_page(  ) {
		new WC_Siawood_Setting_Tab1();
	}

}

To sure that Woocommerce plugin is loaded, so I can use from woocommerce_loaded hook (also I checked it with init, but the results were the same.

And WC_Siawood_Setting_Tab1 class is:


<?php
/**
 * WC_Siawood_Setting_Tab Class File
 *
 * This file creates admin setting tab for this plugin
 *
 * @package    Siawood_Products
 * @author     Mehdi Soltani Neshan <soltani.n.mehdi@gmail.com>
 * @license    https://www.gnu.org/licenses/gpl-3.0.txt GNU/GPLv3
 * @link       https://wpwebmaster.ir
 * @since      1.0.1
 */
namespace Siawood_Products\Includes\Admin;

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

/**
 * WC_Siawood_Setting_Tab Class File
 *
 * This file creates admin setting tab for this plugin
 *
 * @package    Siawood_Products
 * @author     Mehdi Soltani Neshan <soltani.n.mehdi@gmail.com>
 * @link       https://wpwebmaster.ir
 *
 */
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', 'export-woocommerce' );
		parent::__construct();

	}
}

So when I run my plugin and call init_core() method, I got this error:

Fatal error: Class ‘WC_Settings_Page’ not found in …\wp-content\plugins\siawood-products\includes\admin\class-wc-siawood-setting-tab1.php on line 29

It is strange because I hooked it to woocommerce_loaded or plugin_loaded till it will be able load after loading Woocommerce but it doesn’t work.

How can I solve this?


Viewing all articles
Browse latest Browse all 59525

Trending Articles