如何将本机 WooCommerce 身份验证添加到我的自定义 WooCommerce 端点?

发布于 2025-01-09 04:21:58 字数 202 浏览 5 评论 0原文

我有一个自定义 WC API 端点,我想使用 WooCommerce 身份验证来保护它,即:

my-site.com/wp-json/wc/v3/custom?consumer_key=ck...&consumer_secret=cs...

我将如何实现这一点?我知道 JWT 身份验证,但在这种情况下这是不可接受的。

I have a custom WC API endpoint which I want to protect using WooCommerce authentication, ie:

my-site.com/wp-json/wc/v3/custom?consumer_key=ck...&consumer_secret=cs...

How would I achieve this? I know about JWT authentication but that's not acceptible in this case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2025-01-16 04:21:58
add_action('rest_api_init', 'wc_custom_endpoint');
function wc_custom_endpoint(){
  register_rest_route('wc/v3', 'custom', array(
    'methods' => 'GET',
    'callback' => 'return_value',
    'permission_callback' => function($request){      
      return is_user_logged_in();
    }
  ));
}

function return_value(){
    return "this is my custom endpoint!";
}

试试这个

add_action('rest_api_init', 'wc_custom_endpoint');
function wc_custom_endpoint(){
  register_rest_route('wc/v3', 'custom', array(
    'methods' => 'GET',
    'callback' => 'return_value',
    'permission_callback' => function($request){      
      return is_user_logged_in();
    }
  ));
}

function return_value(){
    return "this is my custom endpoint!";
}

Try this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文