| @@ -24,76 +24,122 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | public function display_subscrpt_details( $order ) { |
| 26 | 26 | $histories = Helper::get_subscriptions_from_order( $order->get_id() ); |
| 27 | 27 | |
| 28 | - if ( is_array( $histories ) && count( $histories ) > 0 ) : | |
| 28 | + if ( is_array( $histories ) && count( $histories ) === 0 ) { | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + | |
| 32 | + // Render Subscription Details. | |
| 33 | + ?> | |
| 34 | + | |
| 35 | + <h2 class="woocommerce-order-details__title"><?php esc_html_e( 'Related Subscriptions', 'subscription' ); ?></h2> | |
| 36 | + | |
| 37 | + <?php foreach ( $histories as $history ) : ?> | |
| 38 | + <?php | |
| 39 | + $subscription_id = $history->subscription_id; | |
| 40 | + $subscription_data = Helper::get_subscription_data( $subscription_id ); | |
| 41 | + | |
| 42 | + $subscrpt_status = $subscription_data['status'] ?? '-'; | |
| 43 | + $verbose_status = Helper::get_verbose_status( $subscrpt_status ); | |
| 44 | + | |
| 45 | + $order_item_id = $subscription_data['order']['order_item_id'] ?? $history->order_item_id; | |
| 46 | + $order_item = $order->get_item( $order_item_id ); | |
| 47 | + | |
| 48 | + $start_date_string = $subscription_data['start_date'] ?? ''; | |
| 49 | + $start_date = ! empty( $start_date_string ) ? wp_date( 'F d, Y', strtotime( $start_date_string ) ) : '-'; | |
| 50 | + | |
| 51 | + $next_date_string = $subscription_data['next_date'] ?? ''; | |
| 52 | + $next_date = ! empty( $next_date_string ) ? wp_date( 'F d, Y', strtotime( $next_date_string ) ) : '-'; | |
| 53 | + | |
| 54 | + // Strikes the original amount when a discount carries into renewals. | |
| 55 | + $recurring_amount_string = Helper::get_subscription_recurring_price_html( $subscription_id, $order_item ); | |
| 56 | + | |
| 57 | + $is_grace_period = isset( $subscription_data['grace_period'] ); | |
| 58 | + $grace_remaining = $subscription_data['grace_period']['remaining_days'] ?? 0; | |
| 59 | + | |
| 60 | + $trial = isset( $subscription_data['trial'] ); | |
| 29 | 61 | ?> |
| 30 | - <h2 class="woocommerce-order-details__title"><?php esc_html_e( 'Related Subscriptions', 'wp_subscription' ); ?></h2> | |
| 31 | - <?php if ( ! $order->has_status( 'completed' ) ) : ?> | |
| 32 | - <p><small>Your subscription will be activated when order status is completed.</small></p> | |
| 33 | - <?php endif; ?> | |
| 34 | - <?php | |
| 35 | - foreach ( $histories as $history ) : | |
| 36 | - $order_item = $order->get_item( $history->order_item_id ); | |
| 37 | - $order_item_meta = wc_get_order_item_meta( $history->order_item_id, '_subscrpt_meta', true ); | |
| 38 | 62 | |
| 39 | - $product_name = $order_item->get_name(); | |
| 40 | - $product_link = get_the_permalink( $order_item->get_product_id() ); | |
| 41 | - $post = $history->subscription_id; | |
| 42 | - $cost = get_post_meta( $post, '_subscrpt_price', true ); | |
| 43 | - $order = $order_item->get_order(); | |
| 44 | - $start_date = get_post_meta( $history->subscription_id, '_subscrpt_start_date', true ); | |
| 63 | + <table class="woocommerce-table woocommerce-table--order-details shop_table order_details"> | |
| 64 | + <thead> | |
| 65 | + <tr> | |
| 66 | + <th class="woocommerce-table__product-name product-name"> | |
| 67 | + <?php esc_html_e( 'Subscription ID', 'subscription' ); ?>: | |
| 68 | + </th> | |
| 69 | + <th class="woocommerce-table__product-table product-total"> | |
| 70 | + <?php echo esc_html( $subscription_id ); ?> | |
| 71 | + </th> | |
| 72 | + </tr> | |
| 73 | + </thead> | |
| 74 | + <tbody> | |
| 75 | + <tr> | |
| 76 | + <th scope="row"> | |
| 77 | + <?php esc_html_e( 'Status', 'subscription' ); ?>: | |
| 78 | + </th> | |
| 79 | + <td> | |
| 80 | + <?php if ( $is_grace_period && $grace_remaining > 0 ) : ?> | |
| 81 | + <span class="subscrpt-legacy-status subscrpt-legacy-status--active grace-active"> | |
| 82 | + Active | |
| 45 | 83 | |
| 46 | - $trial_status = null !== $order_item_meta['trial']; | |
| 47 | - ?> | |
| 48 | - <table class="woocommerce-table woocommerce-table--order-details shop_table order_details"> | |
| 49 | - <thead> | |
| 84 | + <?php | |
| 85 | + $grace_remaining_text = sprintf( | |
| 86 | + // translators: Number of days remaining in grace period. | |
| 87 | + __( '%d days remaining!', 'subscription' ), | |
| 88 | + $grace_remaining | |
| 89 | + ); | |
| 90 | + ?> | |
| 91 | + <span class="grace-icon" data-tooltip="<?php echo esc_attr( $grace_remaining_text ); ?>"> | |
| 92 | + <span class="dashicons dashicons-warning"></span> | |
| 93 | + </span> | |
| 94 | + </span> | |
| 95 | + <?php else : ?> | |
| 96 | + <span class="subscrpt-legacy-status subscrpt-legacy-status--<?php echo esc_attr( strtolower( $subscrpt_status ) ); ?>"> | |
| 97 | + <?php echo esc_html( $verbose_status ); ?> | |
| 98 | + </span> | |
| 99 | + <?php endif; ?> | |
| 100 | + </td> | |
| 101 | + </tr> | |
| 102 | + <tr> | |
| 103 | + <th scope="row"> | |
| 104 | + <?php esc_html_e( 'Recurring amount', 'subscription' ); ?>: | |
| 105 | + </th> | |
| 106 | + <td class="woocommerce-table__product-total product-total"> | |
| 107 | + <?php echo wp_kses_post( $recurring_amount_string ); ?> | |
| 108 | + </td> | |
| 109 | + </tr> | |
| 110 | + | |
| 111 | + <?php if ( ! $trial ) : ?> | |
| 50 | 112 | <tr> |
| 51 | - <th class="woocommerce-table__product-name product-name"><?php echo get_the_title( $post ); ?></th> | |
| 52 | - <th class="woocommerce-table__product-table product-total"></th> | |
| 53 | - </tr> | |
| 54 | - </thead> | |
| 55 | - <tbody> | |
| 56 | - <tr class="woocommerce-table__line-item order_item"> | |
| 57 | - <td class="woocommerce-table__product-name product-name"> | |
| 58 | - <a href="<?php echo esc_html( $product_link ); ?>"><?php echo esc_html( $product_name ); ?></a> | |
| 59 | - <strong | |
| 60 | - class="product-quantity">× <?php echo esc_html( $order_item->get_quantity() ); ?></strong> | |
| 113 | + <th scope="row"> | |
| 114 | + <?php esc_html_e( 'Next billing on', 'subscription' ); ?>: | |
| 115 | + </th> | |
| 116 | + <td> | |
| 117 | + <?php echo esc_html( $next_date ); ?> | |
| 61 | 118 | </td> |
| 62 | - <td class="woocommerce-table__product-total product-total"></td> | |
| 63 | 119 | </tr> |
| 64 | - </tbody> | |
| 65 | - <tfoot> | |
| 120 | + <?php else : ?> | |
| 66 | 121 | <tr> |
| 67 | - <th scope="row"><?php esc_html_e( 'Status', 'wp_subscription' ); ?>:</th> | |
| 68 | - <td><?php echo esc_html( get_post_status_object( get_post_status( $post ) )->label ); ?></td> | |
| 122 | + <th scope="row"> | |
| 123 | + <?php esc_html_e( 'Trial', 'subscription' ); ?>: | |
| 124 | + </th> | |
| 125 | + <td> | |
| 126 | + <?php echo esc_html( get_post_meta( $history->subscription_id, '_subscrpt_trial', true ) ); ?> | |
| 127 | + </td> | |
| 69 | 128 | </tr> |
| 70 | 129 | <tr> |
| 71 | - <th scope="row"><?php esc_html_e( 'Recurring amount', 'wp_subscription' ); ?>:</th> | |
| 72 | - <td class="woocommerce-table__product-total product-total"> | |
| 73 | - <?php echo wp_kses_post( Helper::format_price_with_order_item( $cost, $history->order_item_id ) ); ?> | |
| 130 | + <th scope="row"> | |
| 131 | + <?php esc_html_e( 'First billing on', 'subscription' ); ?>: | |
| 132 | + </th> | |
| 133 | + <td> | |
| 134 | + <?php echo esc_html( $start_date ); ?> | |
| 74 | 135 | </td> |
| 75 | 136 | </tr> |
| 76 | - <?php | |
| 77 | - if ( null == $trial_status ) { | |
| 78 | - ?> | |
| 79 | - <tr> | |
| 80 | - <th scope="row"><?php esc_html_e( 'Next billing on', 'wp_subscription' ); ?>:</th> | |
| 81 | - <td><?php echo $order->has_status( 'completed' ) ? esc_html( gmdate( 'F d, Y', get_post_meta( $history->subscription_id, '_subscrpt_next_date', true ) ) ) : '-'; ?></td> | |
| 82 | - </tr> | |
| 83 | - <?php } else { ?> | |
| 84 | - <tr> | |
| 85 | - <th scope="row"><?php esc_html_e( 'Trial', 'wp_subscription' ); ?>:</th> | |
| 86 | - <td><?php echo esc_html( get_post_meta( $history->subscription_id, '_subscrpt_trial', true ) ); ?></td> | |
| 87 | - </tr> | |
| 88 | - <tr> | |
| 89 | - <th scope="row"><?php esc_html_e( 'First billing on', 'wp_subscription' ); ?>:</th> | |
| 90 | - <td><?php echo ! empty( $start_date ) ? esc_html( gmdate( 'F d, Y', $start_date ) ) : '-'; ?></td> | |
| 91 | - </tr> | |
| 92 | - <?php } ?> | |
| 93 | - </tfoot> | |
| 94 | - </table> | |
| 95 | - <?php | |
| 96 | - endforeach; | |
| 97 | - endif; | |
| 137 | + <?php endif; ?> | |
| 138 | + </tbody> | |
| 139 | + </table> | |
| 140 | + <?php endforeach; ?> | |
| 141 | + | |
| 142 | + <?php | |
| 143 | + // End Render Subscription Details. | |
| 98 | 144 | } |
| 99 | 145 | } |