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 ) {



  $response = file_get_contents( $url );


  • I tried your code (although instead hooked it to 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
    Oct 19, 2019 at 19:02
  • i can give you my test wordpress site..please check that i enter this code to function.php in theme editor. url - sms.ultragmtechnologies.com/wp-admin username - sms password-ng4hwvh27c please check this..when i place order this sms service is not working..please check
    – madurange
    Oct 19, 2019 at 19:08
  • if my code is wrong please correct my code please
    – madurange
    Oct 19, 2019 at 19:17
  • DO NOT post login credentials in a public forum. You should IMMEDIATELY delete the login you posted. Second, debugging your code is your job. We'll offer help, but if you need someone to do it for you, this isn't the right place for that. (BTW, your code - at least what is in the function - is fine. If it's not firing when expected, then maybe you need to evaluate which action you're hooking it to. If it's an error, post what the error is. Edit your question with more detail, such as when it should be firing, what the result is, and what the expected result should be.)
    – butlerblog
    Oct 19, 2019 at 20:14
  • it's just a test website that i just create subdomain for my main domain..if the code is work then only i add that code to main website..this is just test website to test my code. i think that was my server issue i checked it with another vps server it's works fine..thank you for your aassist
    – madurange
    Oct 19, 2019 at 20:30

1 Answer 1


I 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 the WP_DEBUG and WP_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 the wp-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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.