After Update to 4.1.6.6 the buyed course is not in list
-
AuthorPosts
-
-
June 23, 2022 at 9:03 PM #837252Anne K. FreyParticipant
I have made an Issue under the wordpress support:
Here is the summery of my findings:
I debuged a bit further in this issue.
It themes to be that the woo_payment plugin has some communication issue after the update.Following observations cut be made in \wp-content\plugins\learnpress-woo-payment\incs\class-lp-wc-hooks.php public function create_lp_order( $wc_order_id, $posted ) L. 183ff
L. 189 The LP_ORDER_CPT comparison (get_post_type( $lp_order_id ) === LP_ORDER_CPT ) is allways falls
L. 218 $item[‘product_id’] is everytime 0.
L.223 LP_Woo_Assign_Course_To_Product::$meta_key_lp_woo_courses_assigned the meta_key ‘_lp_woo_courses_assigned’ is not stored in the database and this list $list_course is everytime empty.
I have made following hotfix to reduce the issue.
/** * Create LP order base on WC order data * Hotfixed Collie-IT, Anne K. Frey 23.06.2022 * Fix issue with lose of course info in lp_order * * @param $wc_order_id * @param $posted * * @throws Exception */ public function create_lp_order( $wc_order_id, $posted ) { $user_id = get_current_user_id(); $user = learn_press_get_user( $user_id ); // Get LP order key related with WC order $lp_order_id = get_post_meta( $wc_order_id, '_learn_press_order_id', true ); // if ( $lp_order_id && get_post_type( $lp_order_id ) === LP_ORDER_CPT ) { // return; // } // Get wc order $wc_order = wc_get_order( $wc_order_id ); if ( ! $wc_order ) { return; } // Get wc order items $wc_items = $wc_order->get_items(); if ( ! $wc_items ) { return; } // Find LP courses in WC order and preparing to create LP Order $lp_order_items = array(); $order_total = 0; $order_subtotal = 0; $opt_buy_course = LP_Gateway_Woo::is_by_courses_via_product(); /** * @var $item WC_Order_Item_Product */ foreach ( $wc_items as $item ) { if ( $opt_buy_course ) { // Get lists course of product $course_id = wc_get_order_item_meta( $item_id, '_course_id' ); $can_purchase = apply_filters( 'learnpress/wc-order/can-purchase-product', true, $course_id ); if ( ! $can_purchase ) { continue; } $course = learn_press_get_course( $course_id ); if ( ! $course || array_key_exists( $course_id, $lp_order_items ) ) { continue; } $order_total += floatval( $course->get_price() ); $order_subtotal += floatval( $course->get_price() ); $lp_order_items[ $course_id ] = array( 'item_type' => get_post_type( $course_id ), 'item_id' => $course_id, 'order_subtotal' => $order_subtotal, 'order_total' => $order_total, ); } else { $item_id = $item['product_id'] ?? 0; $item_type = get_post_type( $item['product_id'] ); if ( ! in_array( $item_type, learn_press_get_item_types_can_purchase() ) ) { return false; } switch ( $item_type ) { case 'product': break; case LP_COURSE_CPT: $order_total += floatval( $item->get_total() ); $order_subtotal += floatval( $item->get_subtotal() ); break; default: $order_total = apply_filters( 'learnpress/wc-order/total/item_type_' . $item_type, $order_total, $item ); $order_subtotal = apply_filters( 'learnpress/wc-order/subtotal/item_type_' . $item_type, $order_subtotal, $item ); break; } $lp_order_items[ $item_id ] = array( 'item_type' => get_post_type( $item_id ), 'item_id' => $item_id, 'order_subtotal' => $order_subtotal, 'order_total' => ! empty( $order_total ) ? $order_total : $order_subtotal, ); } } // If there is no course in wc order if ( empty( $lp_order_items ) ) { return; } // create lp_order $order_data = array( 'post_author' => $user_id, 'post_parent' => '0', 'post_type' => LP_ORDER_CPT, 'post_status' => '', 'ping_status' => 'closed', 'post_title' => __( 'Order on', 'learnpress-woo-payment' ) . ' ' . current_time( 'l jS F Y h:i:s A' ), 'meta_input' => array( '_order_currency' => get_post_meta( $wc_order_id, '_order_currency', true ), '_prices_include_tax' => floatval( $wc_order->get_total_tax() ) > 0 ? 'yes' : 'no', '_user_ip_address' => learn_press_get_ip(), '_user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', '_user_id' => get_post_meta( $wc_order_id, '_customer_user', true ), '_order_total' => ! empty( $order_total ) ? $order_total : $order_subtotal, '_order_subtotal' => $order_subtotal, '_order_key' => apply_filters( 'learn_press_generate_order_key', uniqid( 'order' ) ), '_payment_method' => get_post_meta( $wc_order_id, '_payment_method', true ), '_payment_method_title' => get_post_meta( $wc_order_id, '_payment_method_title', true ), '_created_via' => 'manual', '_woo_order_id' => $wc_order_id, 'user_note' => '', ), ); $lp_order_id = wp_insert_post( $order_data ); update_post_meta( $wc_order_id, '_learn_press_order_id', $lp_order_id ); if ( $opt_buy_course ) { add_post_meta( $lp_order_id, '_lp_create_order_buy_course_via_product', 1 ); } // Handle background, add items to LP Order $params = array( 'lp_order_id' => $lp_order_id, 'lp_order_items' => $lp_order_items, 'lp_no_check_referer' => 1, 'lp_status' => 'lp-' . $wc_order->get_status(), ); $bg = LP_Woo_Payment_Background_Process::instance(); $bg->data( $params )->dispatch(); do_action( 'learn-press/checkout-order-processed', $lp_order_id, null ); do_action( 'learn-press/woo-checkout-create-lp-order-processed', $lp_order_id, null ); }
Annother issue is that the storing of LP()->settings has changed to LP_Settings::instance() but in the woo_payment_addon has not happend. Plaese correct the issue.
-
Due to Privacy&Security matters, Replies to this topic are hidden and can only be seen by our supporters or the topic owner.
Please create a new support topic for your issues.
You can check how to Create an account and Create a Support topic here
-
-
AuthorPosts
You must be logged in to reply to this topic. You can click here