| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Illuminate; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Email |
| 7 |
* |
| 8 |
* @package SpringDevs\Subscription\Illuminate |
| 9 |
*/ |
| 10 |
class Email { |
| 11 |
|
| 12 |
/** |
| 13 |
* The contsructor method. |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
add_action( 'woocommerce_email_after_order_table', array( $this, 'add_subscription_table' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Add subscription sections inside order mail. |
| 21 |
* |
| 22 |
* @param \WC_Order $order Order Object. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function add_subscription_table( $order ) { |
| 27 |
$histories = Helper::get_subscriptions_from_order( $order->get_id() ); |
| 28 |
|
| 29 |
if ( count( $histories ) > 0 ) : |
| 30 |
?> |
| 31 |
<div style="margin-bottom: 40px;"> |
| 32 |
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1"> |
| 33 |
<tbody> |
| 34 |
<tr> |
| 35 |
<h2><?php esc_html_e( 'Related Subscriptions', 'sdevs_subscrpt' ); ?></h2> |
| 36 |
<?php |
| 37 |
if ( ! $order->has_status( 'completed' ) ) : |
| 38 |
?> |
| 39 |
<p><small>Your subscription will be activated when order status is completed.</small></p> |
| 40 |
<?php endif; ?> |
| 41 |
</tr> |
| 42 |
<?php |
| 43 |
foreach ( $histories as $history ) : |
| 44 |
$item = $order->get_item( $history->order_item_id ); |
| 45 |
$item_meta = wc_get_order_item_meta( $history->order_item_id, '_subscrpt_meta', true ); |
| 46 |
$subscription_id = $history->subscription_id; |
| 47 |
$subscription_status_object = get_post_status_object( get_post_status( $subscription_id ) ); |
| 48 |
$cost = get_post_meta( $subscription_id, '_subscrpt_price', true ); |
| 49 |
$has_trial = isset( $item_meta['trial'] ) && strlen( $item_meta['trial'] ) > 2; |
| 50 |
$start_date = get_post_meta( $subscription_id, '_subscrpt_start_date', true ); |
| 51 |
$next_date = get_post_meta( $subscription_id, '_subscrpt_next_date', true ); |
| 52 |
?> |
| 53 |
<tr> |
| 54 |
<th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: center;"><?php echo get_the_title( $subscription_id ); ?></th> |
| 55 |
</tr> |
| 56 |
<tr> |
| 57 |
<th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><a href="<?php echo get_permalink( $item->get_product_id() ); ?>"><?php echo $item->get_name(); ?></a> |
| 58 |
<strong class="product-quantity">× <?php echo esc_html( $item->get_quantity() ); ?></strong> |
| 59 |
</th> |
| 60 |
</tr> |
| 61 |
<tr> |
| 62 |
<th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php esc_html_e( 'Status:', 'sdevs_subscrpt' ); ?> </th> |
| 63 |
<td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo esc_html( $subscription_status_object->label ); ?></td> |
| 64 |
</tr> |
| 65 |
<tr> |
| 66 |
<th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"> |
| 67 |
<?php esc_html_e( 'Recurring amount:', 'sdevs_subscrpt' ); ?> </th> |
| 68 |
<td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo wp_kses_post( Helper::format_price_with_order_item( $cost, $item->get_id() ) ); ?></td> |
| 69 |
</tr> |
| 70 |
<?php if ( ! $has_trial ) { ?> |
| 71 |
<tr> |
| 72 |
<th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php esc_html_e( 'Next billing on', 'sdevs_subscrpt' ); ?>: </th> |
| 73 |
<td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo ! empty( $next_date ) ? esc_html( gmdate( 'F d, Y', $next_date ) ) : '-'; ?></td> |
| 74 |
</tr> |
| 75 |
<?php } else { ?> |
| 76 |
<tr> |
| 77 |
<th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php esc_html_e( 'Trial', 'sdevs_subscrpt' ); ?>: </th> |
| 78 |
<td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo esc_html( $item_meta['trial'] ); ?></td> |
| 79 |
</tr> |
| 80 |
<tr> |
| 81 |
<th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php esc_html_e( 'First billing on', 'sdevs_subscrpt' ); ?>: </th> |
| 82 |
<td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo ! empty( $start_date ) ? esc_html( gmdate( 'F d, Y', $start_date ) ) : '-'; ?></td> |
| 83 |
</tr> |
| 84 |
<?php } ?> |
| 85 |
<tr> |
| 86 |
<th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left; padding-bottom: 30px;"></th> |
| 87 |
</tr> |
| 88 |
<?php |
| 89 |
endforeach; |
| 90 |
?> |
| 91 |
</tbody> |
| 92 |
</table> |
| 93 |
</div> |
| 94 |
<?php |
| 95 |
endif; |
| 96 |
} |
| 97 |
} |
| 98 |
|