LLMS_Shortcode_Checkout::output( array $atts )
Gather a bunch of information and output the actual content for the shortcode.
Parameters Parameters
- $atts
-
(array) (Required) Shortcode atts from originating shortcode.
Return Return
(void)
Source Source
File: includes/shortcodes/class.llms.shortcode.checkout.php
public static function output( $atts ) { global $wp; $atts = $atts ? $atts : array(); $atts['cols'] = isset( $atts['cols'] ) ? $atts['cols'] : 2; self::$uid = get_current_user_id(); $atts['gateways'] = llms()->payment_gateways()->get_enabled_payment_gateways(); $atts['selected_gateway'] = llms()->payment_gateways()->get_default_gateway(); $atts['order_key'] = ''; $atts['field_data'] = array(); if ( isset( $_POST ) && isset( $_POST['action'] ) && 'create_pending_order' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing $atts['field_data'] = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing } elseif ( self::$uid ) { $atts['field_data'] = get_current_user_id(); } self::checkout_wrapper_start(); /** * Allows gateways or third parties to output custom errors before * any core logic is executed. * * This filter returns `false` by default. To output custom errors return * the error message as a string that will be displayed on screen. * * @since Unknown * * @param bool|string $pre_error A custom error message. */ $err = apply_filters( 'lifterlms_pre_checkout_error', false ); if ( $err ) { self::error( $err ); self::checkout_wrapper_end(); return; } llms_print_notices(); // purchase step 1. if ( isset( $_GET['plan'] ) && is_numeric( $_GET['plan'] ) ) { $plan_id = llms_filter_input( INPUT_GET, 'plan', FILTER_SANITIZE_NUMBER_INT ); // Only retrieve if plan is a llms_access_plan and is published. if ( 0 === strcmp( get_post_status( $plan_id ), 'publish' ) && 0 === strcmp( get_post_type( $plan_id ), 'llms_access_plan' ) ) { $coupon = llms()->session->get( 'llms_coupon' ); if ( isset( $coupon['coupon_id'] ) && isset( $coupon['plan_id'] ) ) { if ( $coupon['plan_id'] == $_GET['plan'] ) { $atts['coupon'] = new LLMS_Coupon( $coupon['coupon_id'] ); } else { llms()->session->set( 'llms_coupon', false ); $atts['coupon'] = false; } } else { $atts['coupon'] = false; } // Use posted order key to resume a pending order. if ( isset( $_POST['llms_order_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing $atts['order_key'] = llms_filter_input_sanitize_string( INPUT_POST, 'llms_order_key' ); // Attempt to locate a pending order. } elseif ( self::$uid ) { $pending_order = llms_locate_order_for_user_and_plan( self::$uid, $plan_id ); if ( $pending_order ) { $order = llms_get_post( $pending_order ); $atts['order_key'] = ( 'llms-pending' === $order->get( 'status' ) ) ? $order->get( 'order_key' ) : ''; } } $atts = self::setup_plan_and_form_atts( $plan_id, $atts ); /** * Filter the number of columns used to render the checkout/enrollment form. * * @since Unknown. * @since 5.0.0 Added `$form_location` parameter. * * @param int $cols Number of columns. Accepts 1 or 2. * @param LLMS_Access_Plan $plan Access plan object. * @param string $form_location Form location ID. */ $atts['cols'] = apply_filters( 'llms_checkout_columns', ( $atts['is_free'] || ! $atts['form_fields'] ) ? 1 : $atts['cols'], $atts['plan'], $atts['form_location'] ); self::checkout( $atts ); } else { self::error( __( 'Invalid access plan.', 'lifterlms' ) ); } } elseif ( isset( $wp->query_vars['confirm-payment'] ) ) { $order_key = llms_filter_input_sanitize_string( INPUT_GET, 'order' ); $order = $order_key ? llms_get_order_by_key( $order_key ) : false; if ( ! $order ) { self::error( __( 'Could not locate an order to confirm.', 'lifterlms' ) ); self::checkout_wrapper_end(); return; } $atts = self::setup_plan_and_form_atts( $order->get( 'plan_id' ), $atts ); if ( $order->get( 'coupon_id' ) ) { $atts['coupon'] = new LLMS_Coupon( $order->get( 'coupon_id' ) ); } else { $atts['coupon'] = false; } $atts['selected_gateway'] = llms()->payment_gateways()->get_gateway_by_id( $order->get( 'payment_gateway' ) ); self::confirm_payment( $atts ); } else { self::error( sprintf( __( 'Your cart is currently empty. Click <a href="%s">here</a> to get started.', 'lifterlms' ), llms_get_page_url( 'courses' ) ) ); } self::checkout_wrapper_end(); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
7.0.1 | Fixed issue encountered when trying to confirm payment for a non-existent order. |
7.0.0 | Fixed unclosed div.llms-checkout-wrapper on empty cart. |
5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING . |
5.0.0 | Organize attribute configuration and add new dynamic attributes related to the LLMS_Form post. |
3.35.0 | Sanitize input data. |
3.30.1 | Added check via llms_locate_order_for_user_and_plan() to automatically resume an existing pending order for logged in users if one exists. |
1.0.0 | Introduced. |