| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Frontend; |
| 4 |
|
| 5 |
use SpringDevs\Subscription\Illuminate\Helper; |
| 6 |
|
| 7 |
/** |
| 8 |
* Order class of frontend. |
| 9 |
*/ |
| 10 |
class Order { |
| 11 |
/** |
| 12 |
* Initialize the class. |
| 13 |
*/ |
| 14 |
public function __construct() { |
| 15 |
add_action( 'woocommerce_order_details_after_order_table', array( $this, 'display_subscrpt_details' ) ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Display subscriptions related to the order. |
| 20 |
* |
| 21 |
* @param \WC_Order $order Order Object. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public function display_subscrpt_details( $order ) { |
| 26 |
$histories = Helper::get_subscriptions_from_order( $order->get_id() ); |
| 27 |
|
| 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'] ); |
| 61 |
?> |
| 62 |
|
| 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 |
| 83 |
|
| 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 ) : ?> |
| 112 |
<tr> |
| 113 |
<th scope="row"> |
| 114 |
<?php esc_html_e( 'Next billing on', 'subscription' ); ?>: |
| 115 |
</th> |
| 116 |
<td> |
| 117 |
<?php echo esc_html( $next_date ); ?> |
| 118 |
</td> |
| 119 |
</tr> |
| 120 |
<?php else : ?> |
| 121 |
<tr> |
| 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> |
| 128 |
</tr> |
| 129 |
<tr> |
| 130 |
<th scope="row"> |
| 131 |
<?php esc_html_e( 'First billing on', 'subscription' ); ?>: |
| 132 |
</th> |
| 133 |
<td> |
| 134 |
<?php echo esc_html( $start_date ); ?> |
| 135 |
</td> |
| 136 |
</tr> |
| 137 |
<?php endif; ?> |
| 138 |
</tbody> |
| 139 |
</table> |
| 140 |
<?php endforeach; ?> |
| 141 |
|
| 142 |
<?php |
| 143 |
// End Render Subscription Details. |
| 144 |
} |
| 145 |
} |
| 146 |
|