PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / cart / lp-cart-functions.php

lp-cart-functions.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.3, at inc/cart/lp-cart-functions.php

105 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Return LP_Cart object instance
4 *
5 * @return mixed
6 */
7 function learn_press_get_cart() {
8 return LearnPress::instance()->cart;
9 }
10
11 function learn_press_enable_cart() {
12 return apply_filters( 'learn-press/enable-cart', false );
13 }
14
15 /**
16 * Get description for cart by join all item titles into one
17 *
18 * @return string
19 */
20 function learn_press_get_cart_description() {
21 $items = LearnPress::instance()->cart->get_items();
22 $description = array();
23
24 if ( $items ) {
25 foreach ( $items as $item ) {
26 $description[] = apply_filters( 'learn_press_cart_item_description', get_the_title( $item['item_id'] ) );
27 }
28 }
29
30 return apply_filters( 'learn_press_cart_description', join( ', ', $description ) );
31 }
32
33 function learn_press_get_cart_course_url() {
34 $products = learn_press_get_cart( 'products' );
35 $return = '';
36
37 if ( $products ) {
38 foreach ( $products as $prop ) {
39 $return = get_permalink( $prop['id'] );
40 break;
41 }
42 }
43
44 return apply_filters( 'learn_press_cart_course_url', $return );
45 }
46
47 /**
48 * Return total of cart
49 *
50 * @return mixed
51 */
52 function learn_press_get_cart_total() {
53 return LearnPress::instance()->cart->total;
54 }
55
56 function learn_press_clear_cart_after_payment() {
57 global $wp;
58
59 if ( ! empty( $wp->query_vars['lp-order-received'] ) ) {
60 $order_id = absint( $wp->query_vars['lp-order-received'] );
61 $order_key = LP_Helper::sanitize_params_submitted( $_GET['key'] ?? '' );
62 $order = learn_press_get_order( $order_id );
63
64 if ( $order_id > 0 && $order ) {
65 if ( $order->order_key === $order_key ) {
66 LearnPress::instance()->cart->empty_cart();
67 }
68 }
69 }
70
71 if ( ! is_null( LearnPress::instance()->session ) && LearnPress::instance()->session->order_awaiting_payment > 0 ) {
72 $order = learn_press_get_order( LearnPress::instance()->session->order_awaiting_payment );
73
74 if ( $order && $order->id > 0 ) {
75 if ( ! $order->has_status( array( 'failed', 'pending', 'cancelled' ) ) ) {
76 LearnPress::instance()->cart->empty_cart();
77 LearnPress::instance()->session->order_awaiting_payment = null;
78 }
79 }
80 }
81 }
82 add_action( 'get_header', 'learn_press_clear_cart_after_payment' );
83
84 /**
85 * @param LP_Cart $cart
86 *
87 * @return mixed
88 */
89 function learn_press_custom_checkout_cart( $cart ) {
90 if ( empty( $_REQUEST['single-item'] ) ) {
91 return $cart;
92 }
93
94 $cart = clone $cart;
95 $cart->empty_cart();
96 $items = explode( ',', $_REQUEST['single-item'] );
97
98 foreach ( $items as $item ) {
99 $cart->add_to_cart( $item );
100 }
101
102 return $cart;
103 }
104 add_filter( 'learn_press_checkout_cart', 'learn_press_custom_checkout_cart' );
105