ioanivan
Forum Replies Created
Viewing 4 replies - 1 through 4 (of 4 total)
-
@maizul – sure courses/level-2/?v=3605c251087b
@yulialitvina – i created a code snipped with chat gpt (next time write your message in english)
add_action('woocommerce_order_status_completed', function($order_id){
$order = wc_get_order($order_id);
if (!$order) {
error_log("❌ Order $order_id not found.");
return;
}
$user_id = $order->get_user_id();
if (!$user_id) {
error_log("❌ Order $order_id has no associated user.");
return;
}
foreach ($order->get_items() as $item) {
$product_id = $item->get_product_id();
$course_id = tutor_utils()->get_course_id_by_product($product_id);
if (!$course_id) {
// do nothing
continue;
}
// we check if the user is already enrolled
$already_enrolled = tutor_utils()->is_enrolled($user_id, $course_id);
if ($already_enrolled) {
error_log("ℹ️ User $user_id already enrolled in course $course_id (product $product_id).");
continue;
}
$enrolled = tutor_utils()->enroll_user($user_id, $course_id);
if ($enrolled) {
error_log("✅ Enrolled user $user_id in course $course_id from order $order_id (product $product_id).");
} else {
error_log("❌ Failed to enroll user $user_id in course $course_id (product $product_id) from order $order_id.");
}
}
});Forum: Plugins
In reply to: [Automate Hub Free by Sperse.IO] duplicare resultsOk, thank you so much!
Have a great daY
Still not working 🙁
Hi,
My website it’s hosted in my country: Romania.
Why should i thell them in order to fix the problem?
Thank you!
Viewing 4 replies - 1 through 4 (of 4 total)