我正在尝试将应用购买中的ios与woocommerce购买(网络)同步。因此,当用户在苹果商店购买东西时(产品列表在两侧都是相同的)我想在woocommerce中查看该项目是由该用户购买的。仅供参考,我有一个json api插件,我用来在ios应用程序和网站之间提出请求。知道我怎么能这样做吗?
答案 0 :(得分:0)
这就是我如何解决它
global $woocommerce;
$user = get_user_by('id',$shopId);
if ($user){
wp_set_current_user($shopId,$user->user_login);
wp_set_auth_cookie($shopId);
do_action('wp_login',$user->user_login);
}
if (is_user_logged_in()){
$cart = new WC_Cart();
$checkout = new WC_Checkout();
if ($cart->add_to_cart($productId)){
$orderId = $checkout->create_order(intval($shopId));
}
if (!empty($orderId)){
$order = new WC_Order($orderId);
if (!empty($order)){
$order->update_status("completed","ios app purchase");//I HAD TO SET IT TO COMPLETE SINCE USER BOUGHT IT FROM IOS IN APP PURCHASE
}
//
}
else{
$order = array('fail');
}
}
else{
$order = array();
}
return array($order);