因此,我幫助某人推出了網站,並且當有人購買特定產品時,他們希望獲得折扣產品。我找到了解決方案並實施了該解決方案,並且在該網站的推出過程中發揮了作用,並且不再在購買產品時改變客戶的角色。我試圖從Woothemes獲得支持,他們不支持定製,並且希望他們購買129美元的擴展來處理這個問題。訂單狀態完成後,更改特定產品購買時的用戶角色
有沒有人有這方面的解決方案仍然有效?
這裏是我的代碼:
// Update User on purchase https://gist.github.com/troydean/9322593
function lgbk_add_member($order_id) {
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($items as $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
}
if ($order->user_id > 0 && $product_id == '247' || $order->user_id > 0 && $product_id == '255') {
update_user_meta($order->user_id, 'paying_customer', 1);
$user = new WP_User($order->user_id);
// Remove role
$user->remove_role('customer');
// Add role
$user->add_role('author');
}
}
add_action('woocommerce_order_status_completed', 'lgbk_add_member');
非常感謝您的幫助! –