我已经安装了Dokan插件。它有Dokan\\u Ajax类,带有公共函数add\\u shipping\\u tracking\\u info。
我试图在运气不佳的情况下替换该函数,因此决定在我的插件中添加新函数,以便在Dokan中使用ajax。
使用stackexchange和其他地方描述如何扩展类的答案,这都不成功。希望有人能指出我做错了什么。非常感谢。
Dokan Ajax类文件:
class Dokan_Ajax {
/**
* Singleton object
*
* @staticvar boolean $instance
* @return \\self
*/
public static function init() {
static $instance = false;
if ( !$instance ) {
$instance = new self;
}
return $instance;
}
/**
* Init ajax handlers
*
* @return void
*/
function init_ajax() {
//withdraw note
$withdraw = Dokan_Admin_Withdraw::init();
add_action( \'wp_ajax_dokan_add_shipping_tracking_info\', array( $this, \'add_shipping_tracking_info\' ) );
more add action/filters......
}
public function add_shipping_tracking_info() {
.... original dokan function code ....
}
...... more public functions.....
}
我的插件代码:
class My_Dokan_Ajax extends Dokan_Ajax {
function __construct() {
add_action( \'wp_ajax_dokan_add_shipping_tracking_info\', array( $this, \'OWadd_shipping_tracking_info\' ) );
}
public static function init() {
static $instance = false;
if ( !$instance ) {
$instance = new My_Dokan_Ajax();
}
return $instance;
}
/**
* Add shipping tracking info via ajax
*/
public function OWadd_shipping_tracking_info() {
.... my function code ....
}
}
new My_Dokan_Ajax();
我尝试的第二个代码尝试删除现有函数并添加新函数:
class My_Dokan_Ajax extends Dokan_Ajax {
/**
* Add shipping tracking info via ajax
*/
public function add_shipping_tracking_info() {
.... my new function code ....
}
}
remove_action( \'wp_ajax_dokan_add_shipping_tracking_info\',\'Dokan_Ajax::add_shipping_tracking_info\' );
add_action( \'wp_ajax_dokan_add_shipping_tracking_info\',\'My_Dokan_Ajax::add_shipping_tracking_info\' );