view-order.php 7.77 KB
Newer Older
cyrille's avatar
cyrille committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
<?php
/**
 * View an Order.
 *
 * @package LifterLMS/Templates
 *
 * @since 3.0.0
 * @since 3.33.0 Pass the current order object instance as param for all the actions and filters, plus redundant check on order existence removed.
 * @since 3.35.0 Access `$_GET` data via `llms_filter_input()`.
 * @since 5.4.0 Inform about deleted products.
 * @since 5.9.0 Stop using deprecated `FILTER_SANITIZE_STRING`.
 * @version 5.9.0
 */

defined( 'ABSPATH' ) || exit;

if ( ! $order ) {
	return _e( 'Invalid Order.', 'lifterlms' );
}

$gateway      = $order->get_gateway();
$order_status = $order->get( 'status' );

llms_print_notices();
?>

<div class="llms-sd-section llms-view-order<?php echo apply_filters( 'llms_sd_stacked_order_layout', false, $order ) ? ' llms-stack-cols' : ''; ?>">

	<h2 class="order-title">
		<?php printf( __( 'Order #%d', 'lifterlms' ), $order->get( 'id' ) ); ?>
		<span class="llms-status <?php echo $order_status; ?>"><?php echo $order->get_status_name(); ?></span>
	</h2>

	<?php do_action( 'lifterlms_before_view_order_table', $order ); ?>

	<section class="order-primary">

		<table class="orders-table">
			<tbody>
				<tr>
					<th><?php _e( 'Status', 'lifterlms' ); ?></th>
					<td><?php echo $order->get_status_name(); ?></td>
				</tr>

				<tr>
					<th><?php _e( 'Access Plan', 'lifterlms' ); ?></th>
					<td><?php echo $order->get( 'plan_title' ); ?></td>
				</tr>

				<tr>
					<th><?php _e( 'Product', 'lifterlms' ); ?></th>
					<td>
					<?php if ( llms_get_post( $order->get( 'product_id' ) ) ) : ?>
						<a href="<?php echo get_permalink( $order->get( 'product_id' ) ); ?>"><?php echo $order->get( 'product_title' ); ?></a>
					<?php else : ?>
						<?php echo __( '[DELETED]', 'lifterlms' ) . ' ' . $order->get( 'product_title' ); ?>
					<?php endif; ?>
					</td>
				</tr>
				<?php if ( $order->has_trial() ) : ?>
					<?php if ( $order->has_coupon() && $order->get( 'coupon_amount_trial' ) ) : ?>
						<tr>
							<th><?php _e( 'Original Total', 'lifterlms' ); ?></th>
							<td><?php echo $order->get_price( 'trial_original_total' ); ?></td>
						</tr>

						<tr>
							<th><?php _e( 'Coupon Discount', 'lifterlms' ); ?></th>
							<td>
								<?php echo $order->get_coupon_amount( 'trial' ); ?>
								(<?php echo llms_price( $order->get_price( 'coupon_value_trial', array(), 'float' ) * - 1 ); ?>)
								[<a href="<?php echo get_edit_post_link( $order->get( 'coupon_id' ) ); ?>"><?php echo $order->get( 'coupon_code' ); ?></a>]
							</td>
						</tr>
					<?php endif; ?>

					<tr>
						<th><?php _e( 'Trial Total', 'lifterlms' ); ?></th>
						<td>
							<?php echo $order->get_price( 'trial_total' ); ?>
							<?php printf( _n( 'for %1$d %2$s', 'for %1$d %2$ss', $order->get( 'trial_length' ), 'lifterlms' ), $order->get( 'trial_length' ), $order->get( 'trial_period' ) ); ?>
						</td>
					</tr>
				<?php endif; ?>

				<?php if ( $order->has_discount() ) : ?>
					<tr>
						<th><?php _e( 'Original Total', 'lifterlms' ); ?></th>
						<td><?php echo $order->get_price( 'original_total' ); ?></td>
					</tr>

					<?php if ( $order->has_sale() ) : ?>
						<tr>
							<th><?php _e( 'Sale Discount', 'lifterlms' ); ?></th>
							<td>
								<?php echo $order->get_price( 'sale_price' ); ?>
								(<?php echo llms_price( $order->get_price( 'sale_value', array(), 'float' ) * -1 ); ?>)
							</td>
						</tr>
					<?php endif; ?>

					<?php if ( $order->has_coupon() ) : ?>
						<tr>
							<th><?php _e( 'Coupon Discount', 'lifterlms' ); ?></th>
							<td>
								<?php echo $order->get_coupon_amount( 'regular' ); ?>
								(<?php echo llms_price( $order->get_price( 'coupon_value', array(), 'float' ) * - 1 ); ?>)
								[<a href="<?php echo get_edit_post_link( $order->get( 'coupon_id' ) ); ?>"><?php echo $order->get( 'coupon_code' ); ?></a>]
							</td>
						</tr>
					<?php endif; ?>
				<?php endif; ?>

				<tr>
					<th><?php _e( 'Total', 'lifterlms' ); ?></th>
					<td>
						<?php echo $order->get_price( 'total' ); ?>
						<?php if ( $order->is_recurring() ) : ?>
							<?php
							// phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder -- We don't output the number in the singular so it throws a CS error but it's working as we want it to.
							printf( _n( 'Every %2$s', 'Every %1$d %2$ss', $order->get( 'billing_frequency' ), 'lifterlms' ), $order->get( 'billing_frequency' ), $order->get( 'billing_period' ) );
							// phpcs:enable WordPress.WP.I18n.MissingSingularPlaceholder
							?>
							<?php if ( $order->get( 'billing_cycle' ) > 0 ) : ?>
								<?php printf( _n( 'for %1$d %2$s', 'for %1$d %2$ss', $order->get( 'billing_cycle' ), 'lifterlms' ), $order->get( 'billing_cycle' ), $order->get( 'billing_period' ) ); ?>
							<?php endif; ?>
						<?php else : ?>
							<?php _e( 'One-time', 'lifterlms' ); ?>
						<?php endif; ?>
					</td>
				</tr>

				<tr>
					<th><?php _e( 'Payment Method', 'lifterlms' ); ?></th>
					<td>
						<?php if ( is_wp_error( $gateway ) ) : ?>
							<?php echo $order->get( 'payment_gateway' ); ?>
						<?php else : ?>
							<?php echo $gateway->get_title(); ?>
						<?php endif; ?>
						<?php do_action( 'lifterlms_view_order_after_payment_method', $order ); ?>
					</td>
				</tr>

				<tr>
					<th><?php _e( 'Start Date', 'lifterlms' ); ?></th>
					<td><?php echo $order->get_date( 'date', 'F j, Y' ); ?></td>
				</tr>
				<?php if ( $order->is_recurring() ) : ?>
					<tr>
						<th><?php _e( 'Last Payment Date', 'lifterlms' ); ?></th>
						<td><?php echo $order->get_last_transaction_date( 'llms-txn-succeeded', 'any', 'F j, Y' ); ?></td>
					</tr>

					<?php if ( 'llms-pending-cancel' !== $order_status ) : ?>
						<tr>
							<th><?php _e( 'Next Payment Date', 'lifterlms' ); ?></th>
							<td>
								<?php if ( $order->has_scheduled_payment() ) : ?>
									<?php echo $order->get_next_payment_due_date( 'F j, Y' ); ?>
								<?php else : ?>
									&ndash;
								<?php endif; ?>
							</td>
						</tr>
					<?php endif; ?>
				<?php endif; ?>

				<?php if ( ! $order->is_recurring() || 'lifetime' !== $order->get( 'access_expiration' ) || 'llms-pending-cancel' === $order_status ) : ?>
				<tr>
					<th><?php _e( 'Expiration Date', 'lifterlms' ); ?></th>
					<td><?php echo $order->get_access_expiration_date( 'F j, Y' ); ?></td>
				</tr>
				<?php endif; ?>

				<?php do_action( 'lifterlms_view_order_table_body', $order ); ?>
			</tbody>
		</table>
	</section>

	<aside class="order-secondary">

		<?php if ( $order->is_recurring() ) : ?>

			<?php if ( isset( $_GET['confirm-switch'] ) || 'llms-active' === $order_status || $order->can_resubscribe() ) : ?>

				<?php
				llms_get_template(
					'checkout/form-switch-source.php',
					array(
						'confirm' => llms_filter_input_sanitize_string( INPUT_GET, 'confirm-switch' ),
						'order'   => $order,
					)
				);
				?>

			<?php endif; ?>

			<?php if ( apply_filters( 'llms_allow_subscription_cancellation', true, $order ) && in_array( $order_status, array( 'llms-active', 'llms-on-hold' ) ) ) : ?>

				<form action="" id="llms-cancel-subscription-form" method="POST">

					<?php
					llms_form_field(
						array(
							'columns'     => 12,
							'classes'     => 'llms-button-secondary',
							'id'          => 'llms_cancel_subscription',
							'value'       => __( 'Cancel Subscription', 'lifterlms' ),
							'last_column' => true,
							'required'    => false,
							'type'        => 'submit',
						)
					);
					?>

					<?php wp_nonce_field( 'llms_cancel_subscription', '_cancel_sub_nonce' ); ?>
					<input name="order_id" type="hidden" value="<?php echo $order->get( 'id' ); ?>">

				</form>

			<?php endif; ?>

		<?php endif; ?>

	</aside>

	<div class="clear"></div>

	<?php
	llms_get_template(
		'myaccount/view-order-transactions.php',
		array(
			'transactions' => $transactions,
		)
	);
	?>

	<?php do_action( 'lifterlms_after_view_order_table', $order ); ?>

</div>