HarunRRayhan

LearnDash Redirect Course Homepage after WooCommerce Order

Jun 7th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. // Paste it on yourtheme/woocommerce/checkout/thankyou.php
  2.  
  3. foreach ( $order->get_items() as $item_id => $item ) { // Get All Order Items
  4.     $product_id = $item['product_id']; // Ordered Product ID
  5.     $product_courses = get_post_meta( $product_id, '_related_course'); // Orderd Product Course
  6.  
  7.     if( $product_courses && is_array($product_courses)) { // If it's product and have data
  8.         foreach ($product_courses as  $product_course) {  // Get Each Course ID
  9.  
  10.         $course_link = get_post_permalink($product_course[0]); // First Course Permalink
  11.  
  12.         wp_redirect($course_link); // Redirect to course homepage
  13.         exit(); // Stop execute script
  14.  
  15.         // echo "<pre>";
  16.         // print_r($course_link);
  17.         // echo "</pre>";
  18.         }
  19.     }
  20. }
Add Comment
Please, Sign In to add comment