admin管理员组文章数量:1122832
While I'm trying to extend Woocommerce Rest-API routes with a custom one I face the following problem. I have the following class which tries to hook inside Woocommerce API
class API_LOADER
{
public function init()
{
add_action( 'woocommerce_api_loaded', array( $this, 'load' ) );
}
public function load()
{
//This method will be not called
require_once plugin_dir_path( __FILE__ ).'wc-api-custom.php';
add_filter( 'woocommerce_api_classes', array( $this, 'register' ) );
}
}
but woocommerce_api_loaded
will not trigger any callback.
What I do wrong in this case
While I'm trying to extend Woocommerce Rest-API routes with a custom one I face the following problem. I have the following class which tries to hook inside Woocommerce API
class API_LOADER
{
public function init()
{
add_action( 'woocommerce_api_loaded', array( $this, 'load' ) );
}
public function load()
{
//This method will be not called
require_once plugin_dir_path( __FILE__ ).'wc-api-custom.php';
add_filter( 'woocommerce_api_classes', array( $this, 'register' ) );
}
}
but woocommerce_api_loaded
will not trigger any callback.
What I do wrong in this case
Share Improve this question edited Jun 24, 2019 at 10:19 fefe asked Jun 24, 2019 at 9:57 fefefefe 8943 gold badges14 silver badges34 bronze badges 5 |1 Answer
Reset to default 0What if in your register_rest_route()
call you can pass it the permission_callback option:
'permission_callback' => function () {
return current_user_can('customer');
// OR
return current_user_can('shop_manager');
}
That way you are sure that you are dealing with a logged in Woocommerce user??
These are the two roles that Woocommerce is adding to your site. https://docs.woocommerce.com/document/roles-capabilities/
I know it's not answering your question directly, but I hope this helps! If I am way off, I can take the answer down.
本文标签: hooksExtend Woocommerce rest api routes fails
版权声明:本文标题:hooks - Extend Woocommerce rest api routes fails 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294878a1929451.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
error_log
calls to the plugin on a test instance and then watch the webserver's error log (or PHP's error log, depending on your setup) to see what's happening. I'd start by putting logs in the class WC_Legacy_API constructor, handle_rest_api_requirements (the 'parse_request' hook), and probably then trace out WC_API_REQUEST_VERSION to see which handle function it's calling. – Rup Commented Jun 24, 2019 at 10:49do_action( 'woocommerce_api_loaded' );
to make sure things are triggered. And back to Rup's point, it sounds like you might need to start tracing those calls. Lastly, authors of Woocommerce ask that you not use the same namespace, but rather your own name space. github.com/woocommerce/woocommerce/issues/…. If you use a separate name space, then it's relatively easy to tap into current_user_can() to tie back to Woocommerce functionality to secure your end points. – ChristopherJones Commented Jun 24, 2019 at 12:54