You get order notification emails when you buy things online. However, not many people check their email. Therefore, to keep your customers happy, you should send SMS notifications to them.
To do this, I have created a WordPress plugin called Woocommerce SMS Notification. I am using WC Marketplace and BulkSMS.my as my SMS service provider. I have provided the code snippet of my plugin below. You can also modify it to suit the services you are using.
Like other WooCommerce add-ons/files, I first check if the file is being accessed directly or if Woocommerce is active:
In this example, I am only sending SMS notifications if the order is completed/payment has gone through.
Then, in my function, I get all order details. In my case, I need to get all vendor details based on the products the buyers bought.
Lastly, I type out the SMS and create a loop to send SMSs. I have also sent response emails to myself for debugging purposes. You can turn it off once it is successful.
Note:
- If you want to add a new line to the SMS, make sure you use ‘\r\n’ instead of ‘<br/>’.
- Replace $url with the API you get from your SMS service provider. Different SMS service provider will have different API documentation.
Full code example: