| 1 |
<?php |
| 2 |
/** |
| 3 |
* Return LP_Cart object instance |
| 4 |
* |
| 5 |
* @return LP_Cart |
| 6 |
*/ |
| 7 |
function learn_press_get_cart(): LP_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 |
* @deprecated 4.2.0 |
| 52 |
*/ |
| 53 |
function learn_press_get_cart_total() { |
| 54 |
_deprecated_function( __FUNCTION__, '4.2.0' ); |
| 55 |
return LearnPress::instance()->cart->total; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* @deprecated 4.2.0 |
| 60 |
*/ |
| 61 |
function learn_press_clear_cart_after_payment() { |
| 62 |
global $wp; |
| 63 |
|
| 64 |
if ( ! empty( $wp->query_vars['lp-order-received'] ) ) { |
| 65 |
$order_id = absint( $wp->query_vars['lp-order-received'] ); |
| 66 |
$order_key = LP_Helper::sanitize_params_submitted( $_GET['key'] ?? '' ); |
| 67 |
$order = learn_press_get_order( $order_id ); |
| 68 |
|
| 69 |
if ( $order_id > 0 && $order ) { |
| 70 |
if ( $order->order_key === $order_key ) { |
| 71 |
LearnPress::instance()->cart->empty_cart(); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if ( ! is_null( LearnPress::instance()->session ) && LearnPress::instance()->session->get( 'order_awaiting_payment' ) > 0 ) { |
| 77 |
$order = learn_press_get_order( LearnPress::instance()->session->get( 'order_awaiting_payment' ) ); |
| 78 |
|
| 79 |
if ( $order && $order->id > 0 ) { |
| 80 |
if ( ! $order->has_status( array( 'failed', 'pending', 'cancelled' ) ) ) { |
| 81 |
LearnPress::instance()->cart->empty_cart(); |
| 82 |
LearnPress::instance()->session->remove( 'order_awaiting_payment' ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
//add_action( 'get_header', 'learn_press_clear_cart_after_payment' ); |
| 88 |
|
| 89 |
/** |
| 90 |
* @param LP_Cart $cart |
| 91 |
* |
| 92 |
* @return mixed |
| 93 |
* @deprecated 4.2.0 |
| 94 |
*/ |
| 95 |
/*function learn_press_custom_checkout_cart( $cart ) { |
| 96 |
if ( empty( $_REQUEST['single-item'] ) ) { |
| 97 |
return $cart; |
| 98 |
} |
| 99 |
|
| 100 |
$cart = clone $cart; |
| 101 |
$cart->empty_cart(); |
| 102 |
$items = explode( ',', $_REQUEST['single-item'] ); |
| 103 |
|
| 104 |
foreach ( $items as $item ) { |
| 105 |
$cart->add_to_cart( $item ); |
| 106 |
} |
| 107 |
|
| 108 |
return $cart; |
| 109 |
}*/ |
| 110 |
//add_filter( 'learn_press_checkout_cart', 'learn_press_custom_checkout_cart' ); |
| 111 |
|