| @@ -1,39 +1,98 @@ | ||
| 1 | -<table class="widefat striped"> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Related Subscriptions meta box view. | |
| 4 | + * | |
| 5 | + * @package SpringDevs\Subscription\Admin | |
| 6 | + */ | |
| 7 | + | |
| 8 | +// Exit if accessed directly. | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit; | |
| 11 | +} | |
| 12 | + | |
| 13 | +?> | |
| 14 | +<style> | |
| 15 | + .subscrpt-related-subscriptions td{ | |
| 16 | + vertical-align: middle; | |
| 17 | + } | |
| 18 | +</style> | |
| 19 | + | |
| 20 | +<table class="widefat striped subscrpt-related-subscriptions"> | |
| 2 | 21 | <thead> |
| 3 | 22 | <tr> |
| 4 | - <th></th> | |
| 5 | - <th><?php | |
| 6 | - | |
| 7 | - use SpringDevs\Subscription\Illuminate\Helper; | |
| 8 | - | |
| 9 | - esc_html_e( 'Started on', 'sdevs_subscrpt' ); ?></th> | |
| 10 | - <th><?php esc_html_e( 'Recurring', 'sdevs_subscrpt' ); ?></th> | |
| 11 | - <th><?php esc_html_e( 'Expiry date', 'sdevs_subscrpt' ); ?></th> | |
| 12 | - <th><?php esc_html_e( 'Status', 'sdevs_subscrpt' ); ?></th> | |
| 23 | + <th><?php esc_html_e( 'ID', 'subscription' ); ?></th> | |
| 24 | + <th><?php esc_html_e( 'Product', 'subscription' ); ?></th> | |
| 25 | + <th><?php esc_html_e( 'Recurring', 'subscription' ); ?></th> | |
| 26 | + <th><?php esc_html_e( 'Started on', 'subscription' ); ?></th> | |
| 27 | + <th><?php esc_html_e( 'Expiry date', 'subscription' ); ?></th> | |
| 28 | + <th><?php esc_html_e( 'Status', 'subscription' ); ?></th> | |
| 13 | 29 | </tr> |
| 14 | 30 | </thead> |
| 15 | 31 | <tbody> |
| 16 | 32 | <?php |
| 17 | 33 | foreach ( $histories as $history ) : |
| 18 | - $order_item_id = get_post_meta( $history->subscription_id, '_subscrpt_order_item_id', true ); | |
| 19 | - $order_item = $order->get_item( $history->order_item_id ); | |
| 20 | - $price = get_post_meta( $history->subscription_id, '_subscrpt_price', true ); | |
| 21 | - $trial = get_post_meta( $history->subscription_id, '_subscrpt_trial', true ); | |
| 22 | - $start_date = get_post_meta( $history->subscription_id, '_subscrpt_start_date', true ); | |
| 23 | - $next_date = get_post_meta( $history->subscription_id, '_subscrpt_next_date', true ); | |
| 24 | - $status_object = get_post_status_object( get_post_status( $history->subscription_id ) ); | |
| 34 | + $subscription_id = $history->subscription_id; | |
| 35 | + $subscription_data = SpringDevs\Subscription\Illuminate\Helper::get_subscription_data( $subscription_id ); | |
| 36 | + | |
| 37 | + $subscrpt_status = $subscription_data['status'] ?? ''; | |
| 38 | + $verbose_status = SpringDevs\Subscription\Illuminate\Helper::get_verbose_status( $subscrpt_status ); | |
| 39 | + | |
| 40 | + $order_item_id = get_post_meta( $history->subscription_id, '_subscrpt_order_item_id', true ); | |
| 41 | + $order_item = $order->get_item( $history->order_item_id ); | |
| 42 | + | |
| 43 | + $trial = get_post_meta( $history->subscription_id, '_subscrpt_trial', true ); | |
| 44 | + | |
| 45 | + $start_date = $subscription_data['start_date'] ?? ''; | |
| 46 | + $start_date = ! empty( $start_date ) ? wp_date( 'F j, Y - g:i A', strtotime( $start_date ) ) : '-'; | |
| 47 | + | |
| 48 | + $next_date = $subscription_data['next_date'] ?? ''; | |
| 49 | + $next_date = ! empty( $next_date ) ? wp_date( 'F j, Y - g:i A', strtotime( $next_date ) ) : '-'; | |
| 50 | + | |
| 51 | + // Strikes the original amount when a discount carries into renewals. | |
| 52 | + $price_html = SpringDevs\Subscription\Illuminate\Helper::get_subscription_recurring_price_html( $subscription_id, $order_item ); | |
| 53 | + | |
| 54 | + $is_grace_period = isset( $subscription_data['grace_period'] ); | |
| 55 | + $grace_remaining = $subscription_data['grace_period']['remaining_days'] ?? 0; | |
| 25 | 56 | ?> |
| 26 | 57 | <tr> |
| 27 | 58 | <td> |
| 28 | - <a href="<?php echo esc_html( get_edit_post_link( $history->subscription_id ) ); ?>" target="_blank">#<?php echo esc_html( $history->subscription_id ); ?> - <?php echo esc_html( $order_item->get_name() ); ?></a> | |
| 59 | + <a href="<?php echo esc_html( get_edit_post_link( $subscription_id ) ); ?>" target="_blank">Subscription #<?php echo esc_html( $subscription_id ); ?></a> | |
| 29 | 60 | </td> |
| 30 | 61 | <td> |
| 31 | - <?php echo null == $trial ? ( ! empty( $start_date ) ? esc_html( gmdate( 'F d, Y', $start_date ) ) : '-' ) : '+' . esc_html( $trial ) . ' ' . __( 'free trial', 'sdevs_subscrpt' ); ?> | |
| 62 | + <?php echo esc_html( $order_item->get_name() ); ?> | |
| 32 | 63 | </td> |
| 33 | - <td><?php echo wp_kses_post( Helper::format_price_with_order_item( $price, $order_item->get_id() ) ); ?></td> | |
| 34 | - <td><?php echo esc_html( ! empty( $start_date ) && ! empty( $next_date ) ? ( $trial == null ? gmdate( 'F d, Y', $next_date ) : gmdate( 'F d, Y', $start_date ) ) : '-' ); ?></td> | |
| 35 | - <td><span class="subscrpt-<?php echo esc_attr( $status_object->name ); ?>"><?php echo esc_html( $status_object->label ); ?></span></td> | |
| 64 | + <td> | |
| 65 | + <?php echo wp_kses_post( $price_html ); ?> | |
| 66 | + </td> | |
| 67 | + <td> | |
| 68 | + <?php echo esc_html( $start_date ); ?> | |
| 69 | + </td> | |
| 70 | + <td> | |
| 71 | + <?php echo esc_html( $next_date ); ?> | |
| 72 | + </td> | |
| 73 | + <td> | |
| 74 | + <?php if ( $is_grace_period && $grace_remaining > 0 ) : ?> | |
| 75 | + <span class="subscrpt-legacy-status subscrpt-legacy-status--active grace-active"> | |
| 76 | + Active | |
| 77 | + | |
| 78 | + <?php | |
| 79 | + $grace_remaining_text = sprintf( | |
| 80 | + // translators: Number of days remaining in grace period. | |
| 81 | + __( '%d days remaining!', 'subscription' ), | |
| 82 | + $grace_remaining | |
| 83 | + ); | |
| 84 | + ?> | |
| 85 | + <span class="grace-icon" data-tooltip="<?php echo esc_attr( $grace_remaining_text ); ?>"> | |
| 86 | + <span class="dashicons dashicons-warning"></span> | |
| 87 | + </span> | |
| 88 | + </span> | |
| 89 | + <?php else : ?> | |
| 90 | + <span class="subscrpt-legacy-status subscrpt-legacy-status--<?php echo esc_attr( strtolower( $subscrpt_status ) ); ?>"> | |
| 91 | + <?php echo esc_html( $verbose_status ); ?> | |
| 92 | + </span> | |
| 93 | + <?php endif; ?> | |
| 94 | + </td> | |
| 36 | 95 | </tr> |
| 37 | 96 | <?php |
| 38 | 97 | endforeach; |
| 39 | 98 | ?> |