0

I am struggling with SMS sending in WordPress without plugin, I have a, API, but that API is not working. Example:

function mysite_woocommerce_order_status_processing( $order_id ) {

    $mobile="123456";

    $url="****/api.php?username=******&password=1234&source=UPDATE&dmobile=".$mobile."&message='.$msg.' ";

    $response = wp_remote_get( $url );

    //print_r($response);

}

add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );

I am struggling with above hook, I can send Email through that hook, but not SMS. It would be great if any WordPress developer help me out !

Getting SyntaxError:

JSON.parse: unexpected character at line 1 column 1 of the JSON data

  • JSON.parse, as far I know, is a JavaScript method but you are showing us PHP code. Can you clarify where and where that syntax error appears? – cybmeta Oct 6 '15 at 6:55
1

I think this is the error. The last variable $msg is incorrectly inserted. Here is the corrected code.

function mysite_woocommerce_order_status_processing( $order_id ) {

    $mobile="123456";

    $url="****/api.php?username=******&password=1234&source=UPDATE&dmobile=".$mobile."&message='".$msg."'";

    $response = wp_remote_get( $url );

    //print_r($response);

}

add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );
  • i am sending SMS after woocommerce order is in processing, after place order – affan shaikh Oct 6 '15 at 8:31
-2
function mysite_woocommerce_order_status_processing( $order_id ) {

  $mobile="123456";

  $url="****/api.php?username=******&password=1234&source=UPDATE&dmobile=".$mobile."&message='.$msg.' ";

  $response = file_get_contents( $url );

  //print_r($response);

   }

   add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );

use file_get_contents( $url ) instead of wp_remote_get($url) it will work fine

protected by Community May 27 '16 at 18:21

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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