| 1 |
<?php |
| 2 |
/** |
| 3 |
* Checkout Page Shortcode. |
| 4 |
* |
| 5 |
* @author ThimPress |
| 6 |
* @category Shortcodes |
| 7 |
* @package Learnpress/Shortcodes |
| 8 |
* @version 3.0.0 |
| 9 |
* @extends LP_Abstract_Shortcode |
| 10 |
*/ |
| 11 |
|
| 12 |
defined( 'ABSPATH' ) || exit(); |
| 13 |
|
| 14 |
if ( ! class_exists( 'LP_Shortcode_Checkout' ) ) { |
| 15 |
|
| 16 |
/** |
| 17 |
* Class LP_Shortcode_Checkout |
| 18 |
*/ |
| 19 |
class LP_Shortcode_Checkout extends LP_Abstract_Shortcode { |
| 20 |
|
| 21 |
/** |
| 22 |
* LP_Checkout_Shortcode constructor. |
| 23 |
* |
| 24 |
* @param mixed $atts |
| 25 |
*/ |
| 26 |
public function __construct( $atts = '' ) { |
| 27 |
parent::__construct( $atts ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Output form. |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
public function output() { |
| 36 |
global $wp; |
| 37 |
|
| 38 |
ob_start(); |
| 39 |
if ( isset( $wp->query_vars['lp-order-received'] ) ) { |
| 40 |
$this->_order_received( $wp->query_vars['lp-order-received'] ); |
| 41 |
} else { |
| 42 |
$checkout_cart = learn_press_get_checkout_cart(); |
| 43 |
|
| 44 |
// Check cart has contents |
| 45 |
if ( $checkout_cart && $checkout_cart->is_empty() ) { |
| 46 |
learn_press_get_template( 'checkout/empty-cart.php' ); |
| 47 |
} else { |
| 48 |
learn_press_get_template( 'checkout/form.php' ); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return ob_get_clean(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Output received order information. |
| 57 |
* |
| 58 |
* @param int $order_id |
| 59 |
* |
| 60 |
* @return void |
| 61 |
*/ |
| 62 |
private function _order_received( $order_id = 0 ) { |
| 63 |
$order_id = absint( $order_id ); |
| 64 |
$order_key = LP_Helper::sanitize_params_submitted( $_GET['key'] ?? '' ); |
| 65 |
$order_received = learn_press_get_order( $order_id ); |
| 66 |
|
| 67 |
if ( ! $order_received ) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
if ( $order_received->is_trashed() || $order_received->get_order_key() !== $order_key ) { |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
LP()->session->remove( 'order_awaiting_payment' ); |
| 76 |
LP()->cart->empty_cart(); |
| 77 |
|
| 78 |
learn_press_print_messages(); |
| 79 |
|
| 80 |
learn_press_get_template( 'checkout/order-received.php', array( 'order_received' => $order_received ) ); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|