Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List courses in WooCommerce product w.r.t their menu order score
add_filter('wplms_product_course_order_filter','wplms_course_in_product_order_filter');
function wplms_course_in_product_order_filter($courses){
if(!empty($courses)){
foreach($courses as $course){
$order = get_post_field('menu_order',$course);
if(empty($order))
$order = 0;
if(!empty($new_courses[$order])){
$order = wplms_course_product_recursive_check($new_courses,$order);
$new_courses[$order] = $course;
}
$new_courses[$order] = $course;
}
ksort($new_courses);
print_r($new_courses);
return $new_courses;
}
return $courses;
}
function wplms_course_product_recursive_check($array,$order){
if(empty($array[$order])){
return $order;
}else{
$order++;
wplms_course_product_recursive_check($array,$order);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment