I have found some solutions but they are old like 2014 or more I want an updated solution to this problem.
I am using Liferay DXP version 7.4
I have tried this code but its not working :
LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.fetchLayoutSetPrototype(layoutSetPrototypeId);
String layoutSetPrototypeUuid = layoutSetPrototype.getUuid();
try {
LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(group.getGroupId(), privateLayout, true, layoutSetPrototypeUuid);
LayoutLocalServiceUtil.updatePriorities(group.getGroupId(), privateLayout);
} catch (PortalException e) {
log.error("Failed trying to use site template when creating group", e);
}
The above code is mentioned in this article :(https://liferay.dev/es/ask/questions/development/how-to-add-site-template-to-a-site-programmatically--1)