{"id":1667,"date":"2023-03-25T22:15:46","date_gmt":"2023-03-25T14:15:46","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1667"},"modified":"2023-04-23T21:53:04","modified_gmt":"2023-04-23T13:53:04","slug":"woocommerce-plugin-add_action-always-return-1","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/woocommerce-plugin-add_action-always-return-1\/","title":{"rendered":"woocommerce plugin add_action always return -1"},"content":{"rendered":"<h3>Problem<\/h3>\n<pre><code class=\"language-php\">add_action( &#039;woocommerce_api_wc_gateway_test&#039;, &#039;check_response&#039;);\nfunction check_response() {\n    echo &#039;test&#039;;\n    return &#039;test&#039;;\n}<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>when call <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/loaclhost\/index.php\/wc-api\/WC_Gateway_Test\">https:\/\/loaclhost\/index.php\/wc-api\/WC_Gateway_Test<\/a>, always return httpCode: 200, response body: -1<\/p>\n<h3>Solution<\/h3>\n<pre><code class=\"language-php\">add_action( &#039;woocommerce_api_wc_gateway_test&#039;, &#039;check_response&#039;);\n\nfunction check_response() {\n    echo &#039;{&quot;code&quot;: 200}&#039;;\n    exit;\n}<\/code><\/pre>\n<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/woocommerce\/woocommerce\/issues\/28830\">https:\/\/github.com\/woocommerce\/woocommerce\/issues\/28830<\/a><br \/>\n\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/docs.woocommerce.com\/document\/payment-gateway-api\/\">https:\/\/docs.woocommerce.com\/document\/payment-gateway-api\/<\/a><br \/>\n\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/woocommerce.github.io\/code-reference\/files\/woocommerce-includes-gateways-paypal-includes-class-wc-gateway-paypal-ipn-handler.html\">https:\/\/woocommerce.github.io\/code-reference\/files\/woocommerce-includes-gateways-paypal-includes-class-wc-gateway-paypal-ipn-handler.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem add_action( &#039;woocommerce_api_wc_gateway_te [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[49],"class_list":["post-1667","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-woocommerce"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1667"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1667\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}