Skip to content

Instantly share code, notes, and snippets.

@Anshu-wwc
Anshu-wwc / get-quizzes.php
Created March 30, 2022 03:47
Get all Quizzes : Learnpress
<?php
$user = get_users();
foreach( $user as $key => $value){
$course_applied = learn_press_get_user($value->data->ID, false);
$profile = learn_press_get_profile( $value->data->ID );
$query_quizzes = $profile->query_quizzes( array( 'status' => '' ,'limit'=>'200' ,'paged' => '1') );
if( !empty( $query_quizzes['items'] ) ):
foreach ( $query_quizzes['items'] as $user_quiz ){
$quiz = learn_press_get_quiz( $user_quiz->get_id() );
$quiz_data = $course_applied->get_quiz_data( $quiz->get_id(), $user_quiz->get_course_id() );
@Anshu-wwc
Anshu-wwc / get-lessons-learnpress.php
Created March 29, 2022 17:17
Get Learnpress Lessons of the Course
<?php
$user = get_users();
foreach( $user as $key => $value){
// /* Get purchased Courses */
global $wpdb;
$course_applied = learn_press_get_user($value->data->ID, false);
$user_id = $value->data->ID;
// $where = array( );
$query = $wpdb->prepare( "
SELECT *
@Anshu-wwc
Anshu-wwc / enroll-user.php
Created March 29, 2022 14:21
Enroll user into course : Learndash
<?php
// Learndash enrollment hook
// This code run when the user is enrolling in the course
add_action( 'learndash_update_course_access', 'wwc_update_course_access_webinar', 10, 4 );
function wwc_update_course_access_webinar( $user_id, $course_id, $access_list, $remove ){
// if remove = true then unenroll the user else enroll
$user_id = get_current_user_id();
if ( ( !empty( $user_id ) ) && ( !empty( $course_id ) ) && ( $remove !== true ) ) {
// Write the desired code
@Anshu-wwc
Anshu-wwc / learndash-payment-button.php
Created March 29, 2022 14:19
Edit Learndash Payment Button Interface
<?php
// Filter for payment button
add_filter('learndash_payment_button','wwc_add_webinar_popup',10,2);
function wwc_add_webinar_popup( $join_button, $payment_params ){
// Add content
return $join_button;
}
@Anshu-wwc
Anshu-wwc / add-new-custom-label.php
Created March 29, 2022 12:41
Add new Custom Label : Learndash
<?php
// label : Label
// value : To save value
add_filter('learndash_custom_label_fields', function( $setting_option_fields ){
// Get Learndash Options Array
$setting_option_values = get_option('learndash_settings_custom_labels');
$setting_option_values['session_category_label'] = ! isset( $setting_option_values['session_category_label']) ? '' : $setting_option_values['session_category_label'];
$session_materials = array(
'session_category_label' => array(
@Anshu-wwc
Anshu-wwc / edit-thank-you-page.php
Created March 29, 2022 12:16
Edit Thank you page text : woocommerce
<?php
// Thank you page text
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
// Text to change
$new_str = 'Thank you for buying, Order received successfully.<br />';
$new_str .= 'To Access your dashboard click here <a class="elementor-button-link elementor-button elementor-size-sm" role="button" href="/dashboard">
<span class="elementor-button-content-wrapper">
<span class="elementor-button-text">My Dashboard</span></span></a>';
@Anshu-wwc
Anshu-wwc / add-to-cart-validation.php
Created March 29, 2022 12:15
Limit the product to buy only once woocommerce
<?php
// Buy Only once filter
add_filter('woocommerce_add_to_cart_validation','wwc_bought_before_woocommerce_add_to_cart_validation',20, 2);
function wwc_bought_before_woocommerce_add_to_cart_validation($valid, $product_id){
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id)) {
wc_add_notice( __( 'You can buy this product only once', 'woocommerce' ), 'error' );
$valid = false;
}
return $valid;
@Anshu-wwc
Anshu-wwc / create-shortcode.php
Created March 29, 2022 12:12
Create Shortcode
<?php
// init hook
add_action('init','create_shortcode_order_details');
function create_shortcode_order_details(){
add_shortcode('shortcode','shortcode_callback');
}
// Callback function
function shortcode_callback(){
// variable to hold shortcode data mostly html code
@Anshu-wwc
Anshu-wwc / template-redirect.php
Created March 29, 2022 12:09
Redirect to any page
<?php
// Hook for redirect
add_action( 'template_redirect', 'woocommerce_custom_redirect_after_checkout');
function woocommerce_custom_redirect_after_checkout(){
// Other Code
wp_safe_redirect( site_url("url") );
exit;
@Anshu-wwc
Anshu-wwc / get_enrolled_courses.php
Last active March 29, 2022 14:31
Get enrolled courses of Learndash
<?php
// $user_id Get user Id of the user
$courses = learndash_user_get_enrolled_courses( $user_id, array(), true );
// returns array of course IDs
?>