PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.0.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.0.0
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
← All changes | includes/Traits/Email.php +30 -9 1.4.12.0.0 View file →
@@ -1,10 +1,16 @@
1 1 <?php
2 +/**
3 + * Shared email behaviour for subscription mails.
4 + *
5 + * @package SpringDevs\Subscription\Traits
6 + */
2 7
3 8 namespace SpringDevs\Subscription\Traits;
4 9
5 10 use Exception;
6 11 use SpringDevs\Subscription\Illuminate\Helper;
12 +use SpringDevs\Subscription\Illuminate\Subscription\Subscription;
7 13
8 14 trait Email {
9 15 /**
10 16 * Template list with emails.
@@ -91,9 +97,9 @@
91 97 * @return string
92 98 * @since 3.1.0
93 99 */
94 100 public function get_default_heading(): string {
95 - return __( 'Subscription: #{subscription_id}', 'sdevs_subscrpt' );
101 + return __( 'Subscription: #{subscription_id}', 'subscription' );
96 102 }
97 103
98 104 /**
99 105 * Get the email content in HTML format.
@@ -120,17 +126,26 @@
120 126 *
121 127 * @return string
122 128 */
123 129 public function render_template( string $path ): string {
130 + // Build view subscription url & set it to mail extra data.
131 + $view_subs_endpoint = Subscription::get_user_endpoint( 'view_subs' );
132 + $view_subscription_url = wc_get_endpoint_url( $view_subs_endpoint, $this->subscription_id, wc_get_page_permalink( 'myaccount' ) );
133 +
134 + // Admin-facing mails link to the wp-admin details page instead of My Account.
135 + $admin_subscription_url = admin_url( 'admin.php?page=wp-subscription-details&id=' . $this->subscription_id );
136 +
124 137 return wc_get_template_html(
125 138 $path,
126 139 array_merge(
127 140 array(
128 - 'id' => $this->subscription_id,
129 - 'email_heading' => $this->get_heading(),
130 - 'product_name' => $this->product_name,
131 - 'qty' => $this->qty,
132 - 'amount' => $this->amount,
141 + 'id' => $this->subscription_id,
142 + 'email_heading' => $this->get_heading(),
143 + 'product_name' => $this->product_name,
144 + 'qty' => $this->qty,
145 + 'amount' => $this->amount,
146 + 'view_subscription_url' => $view_subscription_url,
147 + 'admin_subscription_url' => $admin_subscription_url,
133 148 ),
134 149 $this->extra
135 150 ),
136 151 'subscription',
@@ -144,9 +159,9 @@
144 159 * @param string $id id of email.
145 160 * @return void
146 161 */
147 162 public function set_template( string $id ) {
148 - $this->template_base = WP_SUBSCRIPTION_TEMPLATES;
163 + $this->template_base = SUBSCRPT_TEMPLATES;
149 164 if ( isset( $this->templates[ $id ] ) ) {
150 165 $this->template_html = $this->templates[ $id ]['html'];
151 166 $this->template_plain = $this->templates[ $id ]['plain'];
152 167 add_filter( 'woocommerce_template_directory', array( $this, 'filter_woocommerce_template_directory' ), 10, 2 );
@@ -164,14 +179,20 @@
164 179 $order_id = wc_get_order_id_by_order_item_id( $order_item_id );
165 180 } catch ( Exception $e ) {
166 181 return;
167 182 }
168 - $order = wc_get_order( $order_id );
183 + $order = wc_get_order( $order_id );
184 + if ( ! $order ) {
185 + return;
186 + }
187 +
169 188 $order_item = $order->get_item( $order_item_id );
170 189
171 190 $this->product_name = $order_item->get_name();
172 191 $this->qty = $order_item->get_quantity();
173 - $this->amount = Helper::format_price_with_order_item( get_post_meta( $this->subscription_id, '_subscrpt_price', true ), $order_item->get_id() );
192 +
193 + // Text form, not the struck-through markup: every one of these emails renders in plain text too.
194 + $this->amount = Helper::get_subscription_recurring_price_text( $this->subscription_id, $order_item );
174 195 }
175 196
176 197 /**
177 198 * Filter WooCommerce template directory.