

/**
 * ReduceStress course: add buyer to reducestress_course group when course product (ID 53) order completes.
 */
add_action( 'woocommerce_order_status_completed', 'reducestress_add_buyer_to_course_group', 20, 1 );
function reducestress_add_buyer_to_course_group( $order_id ) {
    if ( ! function_exists( 'wc_get_order' ) ) {
        return;
    }

    $order = wc_get_order( $order_id );
    if ( ! $order ) {
        return;
    }

    $user_id = $order->get_user_id();
    if ( ! $user_id ) {
        return;
    }

    $course_product_id = 53; // 7-Day Stress Reset Course
    $has_course = false;

    foreach ( $order->get_items() as $item ) {
        if ( $item->get_product_id() == $course_product_id ) {
            $has_course = true;
            break;
        }
    }

    if ( ! $has_course ) {
        return;
    }

    $group_id = 2; // reducestress_course

    // Try the Groups_User API first, then fall back to Groups_Group_User::create().
    if ( class_exists( 'Groups_User' ) ) {
        $groups_user = Groups_User::get_by_user_id( $user_id );
        if ( $groups_user && ! $groups_user->is_member( $group_id ) ) {
            $groups_user->add_group( $group_id );
            return;
        }
    }

    if ( class_exists( 'Groups_Group_User' ) ) {
        $exists = Groups_Group_User::read( array( 'group_id' => $group_id, 'user_id' => $user_id ) );
        if ( ! $exists ) {
            Groups_Group_User::create( array( 'group_id' => $group_id, 'user_id' => $user_id ) );
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//www.reducestress.site/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url>
		<loc>https://www.reducestress.site/product-category/uncategorized/</loc>
		<lastmod>2026-06-15T16:48:44+00:00</lastmod>
	</url>
</urlset>
<!-- XML Sitemap generated by Yoast SEO -->