PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.10.2
Subscriptions for WooCommerce with Stripe Recurring Payments v1.10.2
2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 All 61 releases
subscription / includes / Frontend / Order.php

Order.php in Subscriptions for WooCommerce with Stripe Recurring Payments 1.10.2, at includes/Frontend/Order.php

155 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $quantity = (int) $order_item->get_quantity();
55 $cost = (float) ( $subscription_data['price'] ?? 0 ) * max( 1, $quantity );
56 $price_excl_tax = (float) $order_item->get_total();
57 $tax_amount = (float) $order_item->get_total_tax();
58
59 if ( $tax_amount > 0 ) {
60 $cost = $price_excl_tax + $tax_amount;
61 $cost = number_format( (float) $cost, 2, '.', '' );
62 }
63
64 $recurring_amount_string = Helper::format_price_with_order_item( $cost, $order_item_id );
65
66 $is_grace_period = isset( $subscription_data['grace_period'] );
67 $grace_remaining = $subscription_data['grace_period']['remaining_days'] ?? 0;
68
69 $trial = isset( $subscription_data['trial'] );
70 ?>
71
72 <table class="woocommerce-table woocommerce-table--order-details shop_table order_details">
73 <thead>
74 <tr>
75 <th class="woocommerce-table__product-name product-name">
76 <?php esc_html_e( 'Subscription ID', 'subscription' ); ?>:
77 </th>
78 <th class="woocommerce-table__product-table product-total">
79 <?php echo esc_html( $subscription_id ); ?>
80 </th>
81 </tr>
82 </thead>
83 <tbody>
84 <tr>
85 <th scope="row">
86 <?php esc_html_e( 'Status', 'subscription' ); ?>:
87 </th>
88 <td>
89 <?php if ( $is_grace_period && $grace_remaining > 0 ) : ?>
90 <span class="subscrpt-active grace-active">
91 Active
92
93 <?php
94 $grace_remaining_text = sprintf(
95 // translators: Number of days remaining in grace period.
96 __( '%d days remaining!', 'subscription' ),
97 $grace_remaining
98 );
99 ?>
100 <span class="grace-icon" data-tooltip="<?php echo esc_attr( $grace_remaining_text ); ?>">
101 <span class="dashicons dashicons-warning"></span>
102 </span>
103 </span>
104 <?php else : ?>
105 <span class="subscrpt-<?php echo esc_attr( strtolower( $subscrpt_status ) ); ?>">
106 <?php echo esc_html( $verbose_status ); ?>
107 </span>
108 <?php endif; ?>
109 </td>
110 </tr>
111 <tr>
112 <th scope="row">
113 <?php esc_html_e( 'Recurring amount', 'subscription' ); ?>:
114 </th>
115 <td class="woocommerce-table__product-total product-total">
116 <?php echo wp_kses_post( $recurring_amount_string ); ?>
117 </td>
118 </tr>
119
120 <?php if ( ! $trial ) : ?>
121 <tr>
122 <th scope="row">
123 <?php esc_html_e( 'Next billing on', 'subscription' ); ?>:
124 </th>
125 <td>
126 <?php echo esc_html( $next_date ); ?>
127 </td>
128 </tr>
129 <?php else : ?>
130 <tr>
131 <th scope="row">
132 <?php esc_html_e( 'Trial', 'subscription' ); ?>:
133 </th>
134 <td>
135 <?php echo esc_html( get_post_meta( $history->subscription_id, '_subscrpt_trial', true ) ); ?>
136 </td>
137 </tr>
138 <tr>
139 <th scope="row">
140 <?php esc_html_e( 'First billing on', 'subscription' ); ?>:
141 </th>
142 <td>
143 <?php echo esc_html( $start_date ); ?>
144 </td>
145 </tr>
146 <?php endif; ?>
147 </tbody>
148 </table>
149 <?php endforeach; ?>
150
151 <?php
152 // End Render Subscription Details.
153 }
154 }
155