| @@ -1,94 +1,94 @@ | ||
| 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 | -use LearnPress\Helpers\Template; | |
| 13 | - | |
| 14 | -defined( 'ABSPATH' ) || exit(); | |
| 15 | - | |
| 16 | -if ( ! class_exists( 'LP_Shortcode_Checkout' ) ) { | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * Class LP_Shortcode_Checkout | |
| 20 | - */ | |
| 21 | - class LP_Shortcode_Checkout extends LP_Abstract_Shortcode { | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * LP_Checkout_Shortcode constructor. | |
| 25 | - * | |
| 26 | - * @param mixed $atts | |
| 27 | - */ | |
| 28 | - public function __construct( $atts = '' ) { | |
| 29 | - parent::__construct( $atts ); | |
| 30 | - } | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * Output form. | |
| 34 | - * | |
| 35 | - * @return string | |
| 36 | - */ | |
| 37 | - public function output() { | |
| 38 | - /** | |
| 39 | - * @var WP $wp | |
| 40 | - */ | |
| 41 | - global $wp; | |
| 42 | - wp_enqueue_style( 'learnpress' ); | |
| 43 | - | |
| 44 | - ob_start(); | |
| 45 | - if ( isset( $wp->query_vars['lp-order-received'] ) ) { | |
| 46 | - $this->order_received( $wp->query_vars['lp-order-received'] ); | |
| 47 | - } else { | |
| 48 | - $checkout_cart = LearnPress::instance()->get_cart(); | |
| 49 | - | |
| 50 | - echo '<div id="learn-press-checkout" class="lp-content-area">'; | |
| 51 | - | |
| 52 | - // Check cart has contents | |
| 53 | - if ( $checkout_cart->is_empty() ) { | |
| 54 | - Template::instance()->get_frontend_template( 'checkout/empty-cart.php' ); | |
| 55 | - } else { | |
| 56 | - wp_enqueue_script( 'lp-checkout' ); | |
| 57 | - $checkout_cart->calculate_totals(); | |
| 58 | - Template::instance()->get_frontend_template( 'checkout/form.php' ); | |
| 59 | - } | |
| 60 | - | |
| 61 | - echo '</div>'; | |
| 62 | - } | |
| 63 | - | |
| 64 | - return ob_get_clean(); | |
| 65 | - } | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * Output received order information. | |
| 69 | - * | |
| 70 | - * @param int $order_id | |
| 71 | - * | |
| 72 | - * @return void | |
| 73 | - */ | |
| 74 | - private function order_received( int $order_id = 0 ) { | |
| 75 | - $order_id = absint( $order_id ); | |
| 76 | - $order_key = LP_Request::get_param( 'key' ); | |
| 77 | - $order_received = learn_press_get_order( $order_id ); | |
| 78 | - if ( ! $order_received ) { | |
| 79 | - return; | |
| 80 | - } | |
| 81 | - | |
| 82 | - if ( $order_received->is_trashed() || $order_received->get_order_key() !== $order_key ) { | |
| 83 | - return; | |
| 84 | - } | |
| 85 | - | |
| 86 | - //LearnPress::instance()->session->remove( 'order_awaiting_payment' ); | |
| 87 | - //LearnPress::instance()->cart->empty_cart(); | |
| 88 | - //learn_press_print_messages(); | |
| 89 | - | |
| 90 | - Template::instance()->get_frontend_template( 'checkout/order-received.php', compact( 'order_received' ) ); | |
| 91 | - } | |
| 92 | - } | |
| 93 | -} | |
| 94 | - | |
| 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 | +use LearnPress\Helpers\Template; | |
| 13 | + | |
| 14 | +defined( 'ABSPATH' ) || exit(); | |
| 15 | + | |
| 16 | +if ( ! class_exists( 'LP_Shortcode_Checkout' ) ) { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * Class LP_Shortcode_Checkout | |
| 20 | + */ | |
| 21 | + class LP_Shortcode_Checkout extends LP_Abstract_Shortcode { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * LP_Checkout_Shortcode constructor. | |
| 25 | + * | |
| 26 | + * @param mixed $atts | |
| 27 | + */ | |
| 28 | + public function __construct( $atts = '' ) { | |
| 29 | + parent::__construct( $atts ); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Output form. | |
| 34 | + * | |
| 35 | + * @return string | |
| 36 | + */ | |
| 37 | + public function output() { | |
| 38 | + /** | |
| 39 | + * @var WP $wp | |
| 40 | + */ | |
| 41 | + global $wp; | |
| 42 | + wp_enqueue_style( 'learnpress' ); | |
| 43 | + | |
| 44 | + ob_start(); | |
| 45 | + if ( isset( $wp->query_vars['lp-order-received'] ) ) { | |
| 46 | + $this->order_received( $wp->query_vars['lp-order-received'] ); | |
| 47 | + } else { | |
| 48 | + $checkout_cart = LearnPress::instance()->get_cart(); | |
| 49 | + | |
| 50 | + echo '<div id="learn-press-checkout" class="lp-content-area">'; | |
| 51 | + | |
| 52 | + // Check cart has contents | |
| 53 | + if ( $checkout_cart->is_empty() ) { | |
| 54 | + Template::instance()->get_frontend_template( 'checkout/empty-cart.php' ); | |
| 55 | + } else { | |
| 56 | + wp_enqueue_script( 'lp-checkout' ); | |
| 57 | + $checkout_cart->calculate_totals(); | |
| 58 | + Template::instance()->get_frontend_template( 'checkout/form.php' ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + echo '</div>'; | |
| 62 | + } | |
| 63 | + | |
| 64 | + return ob_get_clean(); | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Output received order information. | |
| 69 | + * | |
| 70 | + * @param int $order_id | |
| 71 | + * | |
| 72 | + * @return void | |
| 73 | + */ | |
| 74 | + private function order_received( int $order_id = 0 ) { | |
| 75 | + $order_id = absint( $order_id ); | |
| 76 | + $order_key = LP_Request::get_param( 'key' ); | |
| 77 | + $order_received = learn_press_get_order( $order_id ); | |
| 78 | + if ( ! $order_received ) { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + | |
| 82 | + if ( $order_received->is_trashed() || $order_received->get_order_key() !== $order_key ) { | |
| 83 | + return; | |
| 84 | + } | |
| 85 | + | |
| 86 | + //LearnPress::instance()->session->remove( 'order_awaiting_payment' ); | |
| 87 | + //LearnPress::instance()->cart->empty_cart(); | |
| 88 | + //learn_press_print_messages(); | |
| 89 | + | |
| 90 | + Template::instance()->get_frontend_template( 'checkout/order-received.php', compact( 'order_received' ) ); | |
| 91 | + } | |
| 92 | + } | |
| 93 | +} | |
| 94 | + | |