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' );
| improve this answer | |
  • 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

| improve this answer | |

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