admin管理员组文章数量:1303427
I have created a code for WordPress to integrate my custom SMS API. The API URL works fine when I type it on the URL bar; but when it in the code, the API URL will not call. So this code not working when the customer places an order:
add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );
function mysite_woocommerce_order_status_processing( $order_id ) {
$billing_phone="0729424391";
$message="yep";
$url=":9710/http/send-message?username=admin&password=admin&to=".$billing_phone."&messagetype=sms.automatic&message=".$message."'";
$response = file_get_contents( $url );
//print_r($response);
}
I have created a code for WordPress to integrate my custom SMS API. The API URL works fine when I type it on the URL bar; but when it in the code, the API URL will not call. So this code not working when the customer places an order:
add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );
function mysite_woocommerce_order_status_processing( $order_id ) {
$billing_phone="0729424391";
$message="yep";
$url="http://realcam.club:9710/http/send-message?username=admin&password=admin&to=".$billing_phone."&messagetype=sms.automatic&message=".$message."'";
$response = file_get_contents( $url );
//print_r($response);
}
Share
Improve this question
edited Oct 19, 2019 at 18:57
butlerblog
5,1013 gold badges26 silver badges43 bronze badges
asked Oct 19, 2019 at 17:28
madurangemadurange
1
5
|
1 Answer
Reset to default 1I would suggest using the HTTP API that WordPress provides for this purpose. Take a look at the GETting data from an API section for more details on how to get the data from your URL.
To get started, try:
Navigate to your
wp-config.php
file, and set theWP_DEBUG
andWP_DEBUG_LOG
constants to true (do NOT do this on the production server of your site).Next, replace your code with the following:
function mysite_woocommerce_order_status_processing( $order_id ) { $billing_phone = "0729424391"; // TODO Sanitize this input $message = "yep"; // TODO Sanitize this input $url = sprintf( "http://realcam.club:9710/http/send-message?username=admin&password=admin&to=%1$s&messagetype=sms.automatic&message=%2$s", $billing_phone, $message ); try { // GET the response. $response = wp_remote_get( esc_url( $url ) ); // If the response is a WP_Error object, jump to the catch clause. if ( is_wp_error( $response ) ) { throw new UnexpectedValueException( $response->get_error_message() ); } // Log the successful response to the debug log. error_log( print_r( $response, true ) ); } catch ( UnexpectedValueException $e ) { // Log the error to the debug log. error_log( $e ); } } add_action( "woocommerce_order_status_processing", "mysite_woocommerce_order_status_processing" );
and check what's in the
debug.log
file in thewp-content
directory of your WordPress installation.
This code will log the response or, if the request was unsuccessful, an error message to that file. I think it is straightforward enough for you to understand, but if you do have any questions or if anything goes wrong, please let me know.
本文标签: woocommerce offtopicWordPress SMS API integration without plugin error
版权声明:本文标题:woocommerce offtopic - WordPress SMS API integration without plugin error 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741759474a2396314.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
init
and then exited at the end) and it worked fine - I get an "OK" message. What do you mean "the API URL will not call"? Are you getting an error and if so, what is the error? (What do you get as$response
?) – butlerblog Commented Oct 19, 2019 at 19:02