WPLMS Batches
WPLMS Batches is an add-on for sub grouping of students in courses.

How It Works

​

WPLMS BATCHES FAQ

Q1. Selected Old Course Layout on version 4, and Batches Not Visible there, using wplms batches v4.

Add this code in wp-admin > WPLMS > Plugins > Editor > WPLMS Customizer plugin > wplms-customizer.php
1
add_action('wplms_after_course_description',function(){
2
$id = get_the_ID(); $batches = wplms_get_course_batches($id); if(empty($batches))
3
return; $init=Wplms_Batches_Init::init(); $init->show_enroll_button = 1;
4
?>
5
<div class="wplms_batches_wrapper block">
6
<ul>
7
<?php
8
foreach($batches as $batch_id){
9
$init->batch_grid_style('custom',$batch_id);
10
}
11
?>
12
</ul>
13
</div><style>.wplms_batches_wrapper ul{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));grid-gap:1rem}.wplms_batches_wrapper .batch_snapshot{display:flex;flex-direction:row;border:1px solid var(--border);padding:.5rem;position:relative;flex-wrap:wrap;align-items: flex-start}.batch_snapshot .labels{position:absolute;top:.5rem;left:.5rem;z-index:9;background:var(--primary);color:var(--primarycolor);padding:2px 5px;border-radius:2px;display:flex;flex-wrap:wrap}.batch_snapshot .labels>span{text-transform:uppercase;font-size:11px;letter-spacing:1px}.batch_snapshot .batch_image img{border-radius:3px}.batch_image{position:relative;margin:.5rem;flex:1 0 120px}.batch_admins{position:absolute;bottom:.5rem;right:.5rem}.batch_admins img{width:32px;height:32px;border-radius:50%}.batch_content{margin:.5rem;flex:3 0 120px}</style>
14
<?php ?><script>
15
if(typeof localforage != 'undefined'){
16
localforage.getItem('bp_login_token').then(function(token){ function sendEnrollBatchRequest(batch_id){ var xh = new XMLHttpRequest();
17
xh.open('POST', ajaxurl);
18
xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
19
xh.onload = function() {
20
if (xh.status === 200) {
21
let data = JSON.parse(xh.responseText);
22
if(typeof data == 'object' && data.status){
23
document.querySelectorAll('.enrol_in_batch').forEach(function(el){
24
el.parentNode.removeChild(el);
25
});
26
var span = document.createElement('span');
27
span.innerHTML = "<?php _e('Enrolled','wplms-batches');?>";
28
document.querySelector('#batch'+batch_id+' .labels').appendChild(span);
29
}
30
}else if (xhr.status !== 200) {
31
console.log('Something went wrong.Request failed.' + xhr.status);
32
}
33
}
34
xh.send(encodeURI('action=enrol_in_batch&batch_id='+batch_id+'&course_id=<?php echo $id; ?>+&token=' + token));
35
} if(token){
36
var xhr = new XMLHttpRequest();
37
xhr.open('POST', ajaxurl);
38
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
39
xhr.onload = function() {
40
if (xhr.status === 200) {
41
let data = JSON.parse(xhr.responseText);
42
if(typeof data == 'object' && data.status){
43
if(data.enrolled && data.enrolled.length){
44
data.enrolled.map(function(batch_id){
45
var span = document.createElement('span');
46
span.innerHTML = "<?php _e('Enrolled','wplms-batches');?>";
47
document.querySelector('#batch'+batch_id+' .labels').appendChild(span);
48
});
49
}else{ document.querySelectorAll('.batch_content').forEach(function(el){
50
var btn = document.createElement('a');
51
btn.innerHTML = "<?php _e('Enrol Now','wplms-batches');?>";
52
btn.setAttribute('class','enrol_in_batch button is-primary small');
53
if(data.hasOwnProperty('cart_links') && Object.keys(data.cart_links).length){
54
if(data.cart_links.hasOwnProperty(el.getAttribute('data-id')) && data.cart_links[el.getAttribute('data-id')].length){
55
btn.setAttribute('href',data.cart_links[el.getAttribute('data-id')]);
56
} }else{
57
btn.addEventListener('click',function(){
58
btn.innerHTML='...';
59
document.querySelectorAll('.enrol_in_batch').forEach(function(el){
60
if(btn != el){
61
el.style.display='none';
62
}
63
}); sendEnrollBatchRequest(el.getAttribute('data-id'));
64
});
65
} if(el.querySelector('.enroll_now_button')){
66
el.querySelector('.enroll_now_button').remove();
67
} el.appendChild(btn);
68
}); }
69
} }
70
else if (xhr.status !== 200) {
71
console.log('Something went wrong.Request failed.' + xhr.status); }
72
}; xhr.send(encodeURI('action=get_enrolled_batches&course_id=<?php echo $id; ?>&batches='+JSON.stringify(<?php echo json_encode($batches); ?>)+'&token=' + token) );
73
} });
74
}
75
</script><?php
76
});
Copied!