| @@ -75,11 +75,13 @@ | ||
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Display Subscription Content. |
| 78 | 78 | * |
| 79 | - * @param Int $id Post ID. | |
| 79 | + * @param int $id Post ID. | |
| 80 | 80 | */ |
| 81 | - public function view_subscrpt_content( int $id ) { | |
| 81 | + public function view_subscrpt_content( $id ) { | |
| 82 | + $id = absint( $id ); // typecast to int. | |
| 83 | + | |
| 82 | 84 | $subs_post = get_post( $id ); |
| 83 | 85 | $author_id = $subs_post ? (int) $subs_post->post_author : 0; |
| 84 | 86 | $current_user_id = get_current_user_id(); |
| 85 | 87 | $user_is_admin = current_user_can( 'manage_options' ); |
| @@ -110,23 +112,20 @@ | ||
| 110 | 112 | $start_date = $subscription_data['start_date'] ?? ''; |
| 111 | 113 | $start_date = ! empty( $start_date ) ? wp_date( 'F j, Y', strtotime( $start_date ) ) : '-'; |
| 112 | 114 | |
| 113 | 115 | $next_date = $subscription_data['next_date'] ?? ''; |
| 114 | - $next_date = ! empty( $next_date ) ? wp_date( 'F j, Y', strtotime( $next_date ) ) : '-'; | |
| 116 | + $next_date = ! empty( $next_date ) && Helper::has_next_payment( $status ) ? wp_date( 'F j, Y', strtotime( $next_date ) ) : '-'; | |
| 115 | 117 | |
| 116 | 118 | $trial = get_post_meta( $id, '_subscrpt_trial', true ); |
| 117 | 119 | $trial_mode = get_post_meta( $id, '_subscrpt_trial_mode', true ); |
| 118 | 120 | |
| 119 | - $price = $subscription_data['price'] ?? 0; | |
| 120 | - $price_excl_tax = (float) $order_item->get_total(); | |
| 121 | - $tax_amount = (float) $order_item->get_total_tax(); | |
| 121 | + // Undiscounted subtotal, the discount that recurs, tax on the discounted amount, and the renewal total. | |
| 122 | + $display_totals = Helper::get_subscription_display_totals( $id, $order_item ); | |
| 122 | 123 | |
| 123 | - if ( $tax_amount > 0 ) { | |
| 124 | - $price = $price_excl_tax + $tax_amount; | |
| 125 | - $price = number_format( (float) $price, 2, '.', '' ); | |
| 126 | - } else { | |
| 127 | - $tax_amount = 0; | |
| 128 | - } | |
| 124 | + $price = $display_totals['total']; | |
| 125 | + $price_excl_tax = $display_totals['full_excl']; | |
| 126 | + $tax_amount = $display_totals['tax']; | |
| 127 | + $discount = $display_totals['discount']; | |
| 129 | 128 | |
| 130 | 129 | $is_grace_period = isset( $subscription_data['grace_period'] ); |
| 131 | 130 | $grace_remaining = $subscription_data['grace_period']['remaining_days'] ?? 0; |
| 132 | 131 | $grace_end_date = $subscription_data['grace_period']['end_date'] ?? ''; |
| @@ -212,8 +211,13 @@ | ||
| 212 | 211 | } |
| 213 | 212 | |
| 214 | 213 | $action_buttons = apply_filters( 'subscrpt_single_action_buttons', $action_buttons, $id, $subscrpt_nonce, $status ); |
| 215 | 214 | |
| 215 | + // Nothing renews once a subscription has ended, so drop the auto-renewal toggle — Pro adds it through the filter too. | |
| 216 | + if ( ! Helper::has_next_payment( $status ) ) { | |
| 217 | + unset( $action_buttons['auto-renew-on'], $action_buttons['auto-renew-off'] ); | |
| 218 | + } | |
| 219 | + | |
| 216 | 220 | wc_get_template( |
| 217 | 221 | 'myaccount/single.php', |
| 218 | 222 | array( |
| 219 | 223 | 'id' => $id, |
| @@ -231,8 +235,9 @@ | ||
| 231 | 235 | 'related_orders' => $related_orders, |
| 232 | 236 | 'price' => $price, |
| 233 | 237 | 'price_excl_tax' => $price_excl_tax, |
| 234 | 238 | 'tax' => $tax_amount, |
| 239 | + 'discount' => $discount, | |
| 235 | 240 | 'user_cancel' => $user_cancel, |
| 236 | 241 | 'action_buttons' => $action_buttons, |
| 237 | 242 | 'wp_button_class' => wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '', |
| 238 | 243 | ), |
| @@ -305,9 +310,9 @@ | ||
| 305 | 310 | 'author' => get_current_user_id(), |
| 306 | 311 | 'posts_per_page' => 10, |
| 307 | 312 | 'paged' => $current_page, |
| 308 | 313 | 'post_type' => 'subscrpt_order', |
| 309 | - 'post_status' => array( 'pending', 'active', 'on_hold', 'cancelled', 'expired', 'pe_cancelled' ), | |
| 314 | + 'post_status' => array( 'pending', 'active', 'on_hold', 'cancelled', 'expired', 'pe_cancelled', 'completed' ), | |
| 310 | 315 | ); |
| 311 | 316 | |
| 312 | 317 | $postslist = new \WP_Query( $args ); |
| 313 | 318 | wc_get_template( |