Extending WC_REST_Products_Controller
-
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' ) );
The topic ‘Extending WC_REST_Products_Controller’ is closed to new replies.