简体   繁体   中英

Intergrating SMS API for new order in Woocommerce

I am trying to integrate SMS API with woo-commerce for every new order but i am not sure where i am doing wrong. My Task is to send SMS to customer when they place order with Payment Gateway COD (Cash on Delivery). Below is the code i am using. Can anyone tell me what i am doing wrong?

add_action('woocommerce_thankyou', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {

$order = new WC_Order( $order_id );
$customer_id = $order->user_id; 

$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );

$data="userid=[userid]&pwd=[password]&msg=[msg]&mobileno=".$billing_phone; 

$jsonurl = curl_init('http://b2bsms.telecard.com.pk/SMSPortal/Customer/ProcessSMS.aspx');

$json = curl($jsonurl);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($json);
echo $result; 
curl_close($json);

return $order_id; 
}

The error message is

PHP Fatal error: Call to undefined function curl() 

There is no function curl in php, the call to curl_exec runs the http call. You can remove the line $json = curl($jsonurl); in your code, and use the handle $jsonurl everywhere where you are using $json or $ch at the moment:

$jsonurl = curl_init('http://b2bsms.telecard.com.pk/SMSPortal/Customer/ProcessSMS.aspx');
curl_setopt($jsonurl, CURLOPT_POST, true);
curl_setopt($jsonurl, CURLOPT_POSTFIELDS, $data);
curl_setopt($jsonurl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($jsonurl);
echo $result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM