最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

override plugin function in a class not working

programmeradmin3浏览0评论

there is a class "CUSTOM_WC_REST_Orders_Controller" called in a plugin like that:

add_action('woocommerce_init', 'woocommerce_mstore_init');
    function woocommerce_mstore_init()
    {
        include_once plugin_dir_path(__FILE__) . "controllers/flutter-order.php";
    }

while in that flutter-order.php the code is

class CUSTOM_WC_REST_Orders_Controller extends WC_REST_Orders_Controller
    {
        bla bla bla
        function create_new_order($request)
        {
             bla bla bla
        }

    }
new CUSTOM_WC_REST_Orders_Controller();

in my custom plugin I have tried to do this ( but it's not working at all )

add_action('woocommerce_init', 'hmp_custom_woocommerce_mstore_init', 999);
function hmp_custom_woocommerce_mstore_init(){
if (!class_exists('CUSTOM_WC_REST_Orders_Controller') ) {
    return;
}
class hmp_CUSTOM_WC_REST_Orders_Controller extends CUSTOM_WC_REST_Orders_Controller
{
    function create_new_order($request)
    {
        return("test44");
        
}
发布评论

评论列表(0)

  1. 暂无评论