WooCommerce在结帐页面上获取'billing_phone'字段


add_action('woocommerce_order_status_completed', 'my_order_status_completed_sms', 10, 1);
function my_order_status_completed_sms($order_id){
$order = wc_get_order($order_id);
$user_id = $order->get_customer_id();
if($user_id){
$phone_number = get_user_meta($user_id, 'billing_phone', true);
if($phone_number){
cosmosfarm_members_sms_send($phone_number, '#'.$order_id.' is complete. thank you!');
}
}
}

当有人从woocommerce购买时,woocommerce通过插件发送短信。

但是存在一些问题。

如果买家是会员,短信会正常发送出去,没问题。

但是,如果买家不是客人,则不会发送短信。 怎么了?

您的函数依赖于具有user_id并获取该用户的user_meta。

function my_order_status_completed_sms( $order_id ) {
// Get the order object
$order = wc_get_order( $order_id );
// Get the billing phone number from the order
$phone_number = $order->get_billing_phone();
if ( $phone_number ) {
cosmosfarm_members_sms_send( $phone_number, '#' . $order_id . ' is complete. thank you!' );
}
}

使用订单对象,如果为客户或客人输入,则 biling 电话就在那里。

最新更新