• Resolved solidce

    (@solidce)


    I want to create a plugin to extend the WC REST API, and I want to extend the api by extending the WC_REST_Products_Controller which already does 90% of the work.

    It works if I create a snippet, but when I create a plugin instead, I get the “WC_REST_Products_Controller class not found” error, unless I include all the “require_once” directives below, in the correct order.

    That does not look very elegant and robust. Any way to get rid of them and use the autoloading mechanism (or any other mechanism that works with a regular snippet)?

    Do I really have to add all these “require_once” directives in a plugin as opposed to a snippet? My code:

    <?php
    
    require_once plugin_dir_path( __DIR__ ) . 'woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-controller.php';
    require_once plugin_dir_path( __DIR__ ) . 'woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-posts-controller.php';
    require_once plugin_dir_path( __DIR__ ) . 'woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php';
    require_once plugin_dir_path( __DIR__ ) . 'woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php';
    require_once plugin_dir_path( __DIR__ ) . 'woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php';
    
    class PBS_REST_MY_Products_Controller extends WC_REST_Products_Controller {
    	//code here
    }
    
    add_action( 'plugins_loaded', array( 'PBS_REST_MY_Products_Controller', 'init_actions' ) );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Daniyal Ahmed (a11n)

    (@daniyalahmedk)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Best,

    Seems we’ve not had additional inputs on this thread. Thus, we encourage you to make use of the above resources.

    I’ll go ahead and mark the thread as resolved but please feel free to create a new thread if you have further questions.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Extending WC_REST_Products_Controller’ is closed to new replies.