In WooCommerce, I have a script that I am running when my webshop get a new order. This script sends an SMS to me but I would like to send it to the customer as well.
The script is running using a custom function script, just before the Order-received page with information about the order.
How do I get automatic information from the order about the name and phone number the user used?
Reading this: How to get WooCommerce order details post, does not help me, I can get the information I need and the order page fails when I try...
my code today is like this:
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
// Query args
$query21 = http_build_query(array(
'token' => 'My-Token',
'sender' => 'medexit',
'message' => 'NEW ORDER',
'recipients.0.msisdn' => 4511111111,
));
// Send it
$result21 = file_get_contents('https://gatewayapi.com/rest/mtsms?' . $query21);
// exit;
}
}
What do I need is to get the firstname included in the message.
I would like something like:
$firstname = $order_billing_first_name = $order_data['billing']['first_name'];
$phone = $order_billing_phone = $order_data['billing']['phone'];
But nothing seems to works for me.