# learnpress/4.1.7.2/inc/shortcodes/class-lp-shortcode-checkout.php

LearnPress – WordPress LMS Plugin for Create and Sell Online Courses, version 4.1.7.2. 85 lines.

- Page: https://pluginprobe.com/plugins/learnpress/4.1.7.2/code/inc/shortcodes/class-lp-shortcode-checkout.php
- Raw: https://pluginprobe.com/plugins/learnpress/4.1.7.2/raw/inc/shortcodes/class-lp-shortcode-checkout.php
- Modified: 2022-10-03T02:13:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/learnpress/4.1.7.2/code/inc/shortcodes/class-lp-shortcode-checkout.php#L10-L20`.

```php
<?php
/**
 * Checkout Page Shortcode.
 *
 * @author   ThimPress
 * @category Shortcodes
 * @package  Learnpress/Shortcodes
 * @version  3.0.0
 * @extends  LP_Abstract_Shortcode
 */

defined( 'ABSPATH' ) || exit();

if ( ! class_exists( 'LP_Shortcode_Checkout' ) ) {

	/**
	 * Class LP_Shortcode_Checkout
	 */
	class LP_Shortcode_Checkout extends LP_Abstract_Shortcode {

		/**
		 * LP_Checkout_Shortcode constructor.
		 *
		 * @param  mixed $atts
		 */
		public function __construct( $atts = '' ) {
			parent::__construct( $atts );
		}

		/**
		 * Output form.
		 *
		 * @return string
		 */
		public function output() {
			global $wp;

			ob_start();
			if ( isset( $wp->query_vars['lp-order-received'] ) ) {
				$this->_order_received( $wp->query_vars['lp-order-received'] );
			} else {
				$checkout_cart = learn_press_get_checkout_cart();

				// Check cart has contents
				if ( $checkout_cart && $checkout_cart->is_empty() ) {
					learn_press_get_template( 'checkout/empty-cart.php' );
				} else {
					learn_press_get_template( 'checkout/form.php' );
				}
			}

			return ob_get_clean();
		}

		/**
		 * Output received order information.
		 *
		 * @param  int $order_id
		 *
		 * @return void
		 */
		private function _order_received( $order_id = 0 ) {
			$order_id       = absint( $order_id );
			$order_key      = LP_Helper::sanitize_params_submitted( $_GET['key'] ?? '' );
			$order_received = learn_press_get_order( $order_id );

			if ( ! $order_received ) {
				return;
			}

			if ( $order_received->is_trashed() || $order_received->get_order_key() !== $order_key ) {
				return;
			}

			LearnPress::instance()->session->remove( 'order_awaiting_payment' );
			LearnPress::instance()->cart->empty_cart();

			learn_press_print_messages();

			learn_press_get_template( 'checkout/order-received.php', array( 'order_received' => $order_received ) );
		}
	}
}


```
