1 回答
TA贡献1752条经验 获得超4个赞
好的,处理此问题的最佳简单方法是向所有登录的驱动程序用户发送推送通知。基本上,查询在 WordPress 中具有驱动程序角色的运行会话的所有用户。然后,迭代这些尝试向每个人发送通知。像这样更改函数:
/**
* Add a notification when a new woocommerce order is recieved.
*
*/
add_action('woocommerce_thankyou', 'wpmobileapp_woo_order', 10, 1 );
function wpmobileapp_woo_order($order_id) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
$customer_address = $order->get_billing_address();
$user_email = $user_meta->user_email;
$image_url = '';
$link = '';
$title = "new order";
$message = $order . ', ' . $items . ', ' . $customer_address;
// get all users with role 'driver' and an active WP session:
$drivers = get_users([
'role' => 'driver',
'meta_key' => 'session_tokens',
'meta_compare' => 'EXISTS'
]);
// notify each of these by push notification
foreach ($drivers as $driver) {
$driver_email = $driver->user_email;
wpmobileapp_push($title, $message , $image_url, $link, $lang_2letters = 'all', $send_timestamp = '', $driver_email);
error_log("WooCommerce Driver notification: sending push notification to account of $driver_email");
}
}
您可以启用WP_DEBUG并WP_DEBUG_LOG检查哪个驱动程序帐户应该收到推送通知。如果存在日志消息,但您的测试驱动程序用户没有收到通知,可能您需要进一步测试此 wpmobileapp_push 内容。
- 1 回答
- 0 关注
- 86 浏览
添加回答
举报