Home › Forums › Legacy Support › 4.0 Bugs & Issues › code suggestion
- This topic has 5 replies, 3 voices, and was last updated 2 years, 10 months ago by Ada.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
June 14, 2021 at 6:24 am #361311Ernesto LeeParticipanthow can i run this code only on the single course page?? <script> jQuery(window).load(function($){ let enrollNowButton = document.querySelector(".single-course .enrol_in_batch.button.is-primary.small"); let takeThisCourse = document.querySelector('.single-course .course_button.button.full'); if(enrollNowButton.textContent == "Enrol Now" && takeThisCourse.textContent.includes("Take this course") && document.querySelector("body").classList.contains("logged-in")){ takeThisCourse.style.display="none"; jQuery('.single-course .course_pricing>strong').append("Click the Enroll Now button to subscribe in this course."); } }); </script> please suggest me hooks and actionsJune 15, 2021 at 1:47 pm #361529Anshuman SahuKeymasterMaybe try this. :
<script> jQuery(window).load(function($){ let enrollNowButton = document.querySelector(".single-course .enrol_in_batch.button.is-primary.small"); let takeThisCourse = document.querySelector('.single-course .course_button.button.full'); if(enrollNowButton && enrollNowButton.innerText == "Enrol Now" && takeThisCourse && takeThisCourse.innerText.includes("Take this course") && document.querySelector("body").classList.contains("logged-in")){ takeThisCourse.style.display="none"; jQuery('.single-course .course_pricing>strong').append("Click the Enroll Now button to subscribe in this course.");} }); </script>
June 16, 2021 at 5:23 am #361590Ernesto LeeParticipanti want to run this code only on single course page. the issue is if i put this code in wplms >> footer >> google analytic code it loads on every page. because enrollNowButton && takeThisCourse can be find only on single course page. these 2 variable gives error on all other pages because this variable can be find in dom only on single course page. so an action hook is required so that it only runs in the single course page footerJune 17, 2021 at 12:30 pm #361777Anshuman SahuKeymasterin that case please add this code in your wplms-customizer.php file in wplms-customizer plugin :add_action('wp_footer',function(){ if(is_singular('course') || is_singular('course-layout')){ ?> <script> jQuery(window).load(function($){ let enrollNowButton = document.querySelector(".single-course .enrol_in_batch.button.is-primary.small"); let takeThisCourse = document.querySelector('.single-course .course_button.button.full'); if(enrollNowButton && enrollNowButton.innerText == "Enrol Now" && takeThisCourse && takeThisCourse.innerText.includes("Take this course") && document.querySelector("body").classList.contains("logged-in")){ takeThisCourse.style.display="none"; jQuery('.single-course .course_pricing>strong').append("Click the Enroll Now button to subscribe in this course.");} }); </script> <?php } });
June 20, 2021 at 9:32 am #362084Ernesto LeeParticipantthanks it worked.June 21, 2021 at 5:19 am #362111AdaParticipantThank-you for confirming. closing this topic. -
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
- The topic ‘code suggestion’ is closed to new replies.