WPLMS
  • About
  • Documentation Structure
  • Changelog
  • Installation
    • Installing WPLMS on a Fresh WP Install
    • Upgrading from a 3.x or an older WPLMS Version.
    • Installing WPLMS on an Existing WordPress site.
  • Administrator Guide
    • Beginners Guide
    • Setting Up
      • Login and Registration
      • Directories
        • Course Layouts
        • Profile Layouts
      • Menus
      • Customizer / Colors / Fonts
        • Header
      • Vibe Options Panel
      • Sidebars & Widgets
      • Footer
      • Icon Set
      • Required pages for WPLMS
      • BuddyPress Single page
  • Extending Options
    • Adding Captcha to Forms
    • Adding Custom Sections in Courses
  • Members Area
    • Dashboards
    • Profile
  • Setting Up Layouts
  • PWA
  • Android App
  • Translation Guide
    • WPML Integration - MultiLingual sites
    • Buddypress Translation
      • Buddy Press Translation Guide Using Loco Translator
    • Theme and Plugins Translation
      • Translation FAQs
      • Translate Using Loco Translate Plugin
  • Admin Guide FAQs
  • Instructor Guide
    • Creating Courses
    • Customize Dashboard
    • Assignments
    • Shortcodes
    • FAQs
  • Student Guide
    • Members Area
      • Dashboard
      • Profile
      • Courses
      • My Quizzes
      • My Assignments
      • Notes & Review
    • Enroll in Courses
    • Pursuing Courses
      • Pursuing Quizzes
  • Extensions & Addons
    • List of All Addons
    • Extended Addons
      • WPLMS SphereEngine
      • WPLMS Parent User
      • WPLMS Mailchimp
      • WPLMS PDF Certificates
      • WPLMS Get Response
      • WPLMS GroundHogg
      • WPLMS Active Campaign
      • WPLMS Custom Learning Paths
      • WPLMS Unit Timings
      • WPLMS Phone Auth
      • Vibe Appointments
      • WPLMS Attendance
      • WPLMS Woocommerce
      • WPLMS Batches
      • WPLMS EventOn
      • VideoVibe
      • Video Conferencing
        • Lessonspace
        • Vibe Zoom
        • Vibe BigBlueButton
        • Vibe Jitsi
  • Developer Guide
    • Authentication
    • API EndPoints
      • Courses
        • User Actions
    • Customisation tips
    • Custom Extension
  • FAQs
    • FAQs
      • Importing Revolution Slider
      • Importing LayerSlider
    • App FAQ's
Powered by GitBook
On this page
  • How It Works
  • WPLMS BATCHES FAQ

Was this helpful?

  1. Extensions & Addons
  2. Extended Addons

WPLMS Batches

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

PreviousWPLMS WoocommerceNextWPLMS EventOn

Last updated 4 years ago

Was this helpful?

How It Works

Purchase Link:

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

add_action('wplms_after_course_description',function(){ 
 $id = get_the_ID();  $batches = wplms_get_course_batches($id);    if(empty($batches))
      return;    $init=Wplms_Batches_Init::init();    $init->show_enroll_button = 1;
      ?>
      <div class="wplms_batches_wrapper block">
        <ul>
        <?php
          foreach($batches as $batch_id){
            $init->batch_grid_style('custom',$batch_id);
          }
        ?>
        </ul>
      </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>
      <?php    ?><script>
      if(typeof localforage != 'undefined'){
        localforage.getItem('bp_login_token').then(function(token){          function sendEnrollBatchRequest(batch_id){            var xh = new XMLHttpRequest();
            xh.open('POST', ajaxurl);
            xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xh.onload = function() {
              if (xh.status === 200) {
                              let data = JSON.parse(xh.responseText);
                              if(typeof data == 'object' && data.status){
                                document.querySelectorAll('.enrol_in_batch').forEach(function(el){
                                  el.parentNode.removeChild(el);
                                });
                                var span = document.createElement('span');
                  span.innerHTML = "<?php _e('Enrolled','wplms-batches');?>";
                            document.querySelector('#batch'+batch_id+' .labels').appendChild(span);
                              }
              }else if (xhr.status !== 200) {
                            console.log('Something went wrong.Request failed.' + xhr.status);
                          }
            }
            xh.send(encodeURI('action=enrol_in_batch&batch_id='+batch_id+'&course_id=<?php echo $id; ?>+&token=' + token));
          }          if(token){
            var xhr = new XMLHttpRequest();
            xhr.open('POST', ajaxurl);
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.onload = function() {
                          if (xhr.status === 200) {
                              let data = JSON.parse(xhr.responseText);
                              if(typeof data == 'object' && data.status){
                                if(data.enrolled && data.enrolled.length){
                                  data.enrolled.map(function(batch_id){
                                    var span = document.createElement('span');
                      span.innerHTML = "<?php _e('Enrolled','wplms-batches');?>";
                                    document.querySelector('#batch'+batch_id+' .labels').appendChild(span);
                                  });
                                }else{                                document.querySelectorAll('.batch_content').forEach(function(el){
                                  var btn = document.createElement('a');
                      btn.innerHTML = "<?php _e('Enrol Now','wplms-batches');?>";
                      btn.setAttribute('class','enrol_in_batch button is-primary small');
                      if(data.hasOwnProperty('cart_links') && Object.keys(data.cart_links).length){
                        if(data.cart_links.hasOwnProperty(el.getAttribute('data-id')) && data.cart_links[el.getAttribute('data-id')].length){
                          btn.setAttribute('href',data.cart_links[el.getAttribute('data-id')]);
                        }                      }else{
                        btn.addEventListener('click',function(){
                          btn.innerHTML='...';
                          document.querySelectorAll('.enrol_in_batch').forEach(function(el){
                                          if(btn != el){
                                            el.style.display='none';
                                          }
                                        });                          sendEnrollBatchRequest(el.getAttribute('data-id'));
                        });
                      }                      if(el.querySelector('.enroll_now_button')){
                        el.querySelector('.enroll_now_button').remove();
                      }                                  el.appendChild(btn);
                                });                                }
                              }                          }
                          else if (xhr.status !== 200) {
                              console.log('Something went wrong.Request failed.' + xhr.status);                          }
                      };                      xhr.send(encodeURI('action=get_enrolled_batches&course_id=<?php echo $id; ?>&batches='+JSON.stringify(<?php echo json_encode($batches); ?>)+'&token=' + token) );
                    }        });
      }
    </script><?php
});
https://wplms.io/downloads/wplms-batches/