| @@ -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. |
| @@ -23,8 +29,12 @@ | ||
| 23 | 29 | 'subscrpt_subscription_cancelled_email' => array( |
| 24 | 30 | 'html' => 'emails/subscription-cancelled-html.php', |
| 25 | 31 | 'plain' => 'emails/plains/subscription-cancelled-plain.php', |
| 26 | 32 | ), |
| 33 | + 'subscrpt_subscription_stock_paused_email' => array( | |
| 34 | + 'html' => 'emails/subscription-stock-paused-html.php', | |
| 35 | + 'plain' => 'emails/plains/subscription-stock-paused-plain.php', | |
| 36 | + ), | |
| 27 | 37 | 'subscrpt_renew_reminder' => array( |
| 28 | 38 | 'html' => 'emails/renew-reminder-html.php', |
| 29 | 39 | 'plain' => 'emails/plains/renew-reminder-plain.php', |
| 30 | 40 | ), |
| @@ -91,9 +101,9 @@ | ||
| 91 | 101 | * @return string |
| 92 | 102 | * @since 3.1.0 |
| 93 | 103 | */ |
| 94 | 104 | public function get_default_heading(): string { |
| 95 | - return __( 'Subscription: #{subscription_id}', 'sdevs_subscrpt' ); | |
| 105 | + return __( 'Subscription: #{subscription_id}', 'subscription' ); | |
| 96 | 106 | } |
| 97 | 107 | |
| 98 | 108 | /** |
| 99 | 109 | * Get the email content in HTML format. |
| @@ -120,17 +130,26 @@ | ||
| 120 | 130 | * |
| 121 | 131 | * @return string |
| 122 | 132 | */ |
| 123 | 133 | public function render_template( string $path ): string { |
| 134 | + // Build view subscription url & set it to mail extra data. | |
| 135 | + $view_subs_endpoint = Subscription::get_user_endpoint( 'view_subs' ); | |
| 136 | + $view_subscription_url = wc_get_endpoint_url( $view_subs_endpoint, $this->subscription_id, wc_get_page_permalink( 'myaccount' ) ); | |
| 137 | + | |
| 138 | + // Admin-facing mails link to the wp-admin details page instead of My Account. | |
| 139 | + $admin_subscription_url = admin_url( 'admin.php?page=wp-subscription-details&id=' . $this->subscription_id ); | |
| 140 | + | |
| 124 | 141 | return wc_get_template_html( |
| 125 | 142 | $path, |
| 126 | 143 | array_merge( |
| 127 | 144 | 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, | |
| 145 | + 'id' => $this->subscription_id, | |
| 146 | + 'email_heading' => $this->get_heading(), | |
| 147 | + 'product_name' => $this->product_name, | |
| 148 | + 'qty' => $this->qty, | |
| 149 | + 'amount' => $this->amount, | |
| 150 | + 'view_subscription_url' => $view_subscription_url, | |
| 151 | + 'admin_subscription_url' => $admin_subscription_url, | |
| 133 | 152 | ), |
| 134 | 153 | $this->extra |
| 135 | 154 | ), |
| 136 | 155 | 'subscription', |
| @@ -164,14 +183,20 @@ | ||
| 164 | 183 | $order_id = wc_get_order_id_by_order_item_id( $order_item_id ); |
| 165 | 184 | } catch ( Exception $e ) { |
| 166 | 185 | return; |
| 167 | 186 | } |
| 168 | - $order = wc_get_order( $order_id ); | |
| 187 | + $order = wc_get_order( $order_id ); | |
| 188 | + if ( ! $order ) { | |
| 189 | + return; | |
| 190 | + } | |
| 191 | + | |
| 169 | 192 | $order_item = $order->get_item( $order_item_id ); |
| 170 | 193 | |
| 171 | 194 | $this->product_name = $order_item->get_name(); |
| 172 | 195 | $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() ); | |
| 196 | + | |
| 197 | + // Text form, not the struck-through markup: every one of these emails renders in plain text too. | |
| 198 | + $this->amount = Helper::get_subscription_recurring_price_text( $this->subscription_id, $order_item ); | |
| 174 | 199 | } |
| 175 | 200 | |
| 176 | 201 | /** |
| 177 | 202 | * Filter WooCommerce template directory. |