| @@ -162,8 +162,18 @@ | ||
| 162 | 162 | |
| 163 | 163 | <?php |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | + protected function getEventInfo() | |
| 167 | + { | |
| 168 | + return [ | |
| 169 | + 'item' => $this->currentCartItem, | |
| 170 | + 'cart' => null, | |
| 171 | + 'product' => $this->product, | |
| 172 | + 'variant' => null, | |
| 173 | + ]; | |
| 174 | + } | |
| 175 | + | |
| 166 | 176 | public function renderDetails() |
| 167 | 177 | { |
| 168 | 178 | ?> |
| 169 | 179 | |
| @@ -173,8 +183,9 @@ | ||
| 173 | 183 | $this->renderTitles(); |
| 174 | 184 | $this->renderItemPrice(); |
| 175 | 185 | $this->renderQuantity(); |
| 176 | 186 | (new CartItemRenderer($this->currentCartItem))->renderChildVariants(); |
| 187 | + do_action('fluent_cart/cart/line_item/line_meta', $this->getEventInfo()); | |
| 177 | 188 | ?> |
| 178 | 189 | |
| 179 | 190 | </div> |
| 180 | 191 | |
| @@ -185,9 +196,11 @@ | ||
| 185 | 196 | |
| 186 | 197 | public function renderTitles() |
| 187 | 198 | { |
| 188 | 199 | $postTitle = Arr::get($this->currentCartItem, 'post_title', ''); |
| 189 | - $variationTitle = Arr::get($this->currentCartItem, 'title', ''); | |
| 200 | + // The Cart model already resolves & appends variation_display_title on | |
| 201 | + // every cart item (Cart::getCartDataAttribute), so just read it. | |
| 202 | + $variationTitle = (string) Arr::get($this->currentCartItem, 'variation_display_title', Arr::get($this->currentCartItem, 'title', '')); | |
| 190 | 203 | $variationType = Arr::get($this->currentCartItem, 'variation_type', 'simple'); |
| 191 | 204 | |
| 192 | 205 | $aria_label = sprintf( |
| 193 | 206 | /* translators: 1: Post or product title */ |
| @@ -217,9 +230,13 @@ | ||
| 217 | 230 | } |
| 218 | 231 | |
| 219 | 232 | public function renderItemPrice() |
| 220 | 233 | { |
| 221 | - $price = Helper::toDecimal(Arr::get($this->currentCartItem, 'unit_price', 0)); | |
| 234 | + $price = Helper::toDecimal(Arr::get( | |
| 235 | + $this->currentCartItem, | |
| 236 | + 'line_meta.original_unit_price', | |
| 237 | + Arr::get($this->currentCartItem, 'unit_price', 0) | |
| 238 | + )); | |
| 222 | 239 | $quantity = Arr::get($this->currentCartItem, 'quantity', 1); |
| 223 | 240 | |
| 224 | 241 | ?> |
| 225 | 242 | <div class="fct-cart-item-price <?php echo $quantity <= 1 ? 'item-price-hidden' : '' ?>"> |
| @@ -310,9 +327,14 @@ | ||
| 310 | 327 | |
| 311 | 328 | public function renderItemTotal() |
| 312 | 329 | { |
| 313 | 330 | $quantity = Arr::get($this->currentCartItem, 'quantity', 0); |
| 314 | - $totalPrice = Arr::get($this->currentCartItem, 'unit_price', 0) * $quantity; | |
| 331 | + $displayUnitPrice = Arr::get( | |
| 332 | + $this->currentCartItem, | |
| 333 | + 'line_meta.original_unit_price', | |
| 334 | + Arr::get($this->currentCartItem, 'unit_price', 0) | |
| 335 | + ); | |
| 336 | + $totalPrice = $displayUnitPrice * $quantity; | |
| 315 | 337 | |
| 316 | 338 | if (Arr::get($this->currentCartItem, 'other_info.payment_type', 'onetime') == 'subscription') { |
| 317 | 339 | if (Arr::get($this->currentCartItem, 'other_info.manage_setup_fee') == 'yes') { |
| 318 | 340 | $signupFee = Arr::get($this->currentCartItem, 'other_info.signup_fee', 0); |
| @@ -347,10 +369,29 @@ | ||
| 347 | 369 | } |
| 348 | 370 | |
| 349 | 371 | public function renderTotal() |
| 350 | 372 | { |
| 351 | - | |
| 352 | - $subtotal = CartCheckoutHelper::make()->getItemsAmountSubtotal(true, true); | |
| 373 | + $cartItems = CartCheckoutHelper::make()->getItems(); | |
| 374 | + $grossTotal = 0; | |
| 375 | + foreach ($cartItems as $item) { | |
| 376 | + $paymentType = Arr::get($item, 'other_info.payment_type', ''); | |
| 377 | + $qty = max(1, (int) Arr::get($item, 'quantity', 1)); | |
| 378 | + $displayUnitPrice = (int) Arr::get( | |
| 379 | + $item, | |
| 380 | + 'line_meta.original_unit_price', | |
| 381 | + Arr::get($item, 'unit_price', 0) | |
| 382 | + ); | |
| 383 | + if ($paymentType === 'subscription') { | |
| 384 | + if ((int) Arr::get($item, 'other_info.trial_days', 0) > 0) { | |
| 385 | + $grossTotal += (int) Arr::get($item, 'other_info.signup_fee', 0); | |
| 386 | + } else { | |
| 387 | + $grossTotal += $displayUnitPrice * $qty + (int) Arr::get($item, 'other_info.signup_fee', 0); | |
| 388 | + } | |
| 389 | + } else { | |
| 390 | + $grossTotal += $displayUnitPrice * $qty; | |
| 391 | + } | |
| 392 | + } | |
| 393 | + $subtotal = Helper::toDecimal($grossTotal); | |
| 353 | 394 | $aria_label = sprintf( |
| 354 | 395 | /* translators: 1: Total price */ |
| 355 | 396 | __('Total cart price: %1$s', 'fluent-cart'), |
| 356 | 397 | esc_attr($subtotal) |
| @@ -362,9 +403,17 @@ | ||
| 362 | 403 | class="fct-cart-total-wrapper" |
| 363 | 404 | role="region" |
| 364 | 405 | aria-label="<?php esc_attr_e('Cart Total', 'fluent-cart'); ?>" |
| 365 | 406 | > |
| 366 | - <span><?php echo esc_html__('Total', 'fluent-cart'); ?>:</span> | |
| 407 | + <span><?php | |
| 408 | + /** | |
| 409 | + * Filters the cart total label. Lets a caller relabel it without | |
| 410 | + * reimplementing this markup; the default renders exactly as before. | |
| 411 | + * | |
| 412 | + * @param string $label | |
| 413 | + */ | |
| 414 | + echo esc_html(apply_filters('fluent_cart/cart/total_label', __('Total', 'fluent-cart'))); | |
| 415 | + ?></span> | |
| 367 | 416 | <span |
| 368 | 417 | data-fluent-cart-cart-total-price |
| 369 | 418 | aria-live="polite" |
| 370 | 419 | aria-label="<?php echo esc_attr($aria_label); ?>" |
| @@ -407,13 +456,21 @@ | ||
| 407 | 456 | public function renderCheckoutButton() |
| 408 | 457 | { |
| 409 | 458 | ?> |
| 410 | 459 | |
| 411 | - <a class="checkout-button" | |
| 460 | + <a class="checkout-button fct-primary-btn" | |
| 412 | 461 | href="<?php echo esc_attr($this->storeSettings->getCheckoutPage()); ?>" |
| 413 | 462 | role="button" |
| 414 | 463 | aria-label="<?php esc_attr_e('Go to checkout page', 'fluent-cart'); ?>"> |
| 415 | - <?php esc_html_e('Go to Checkout', 'fluent-cart'); ?> | |
| 464 | + <?php | |
| 465 | + /** | |
| 466 | + * Filters the cart checkout button text. Lets a caller relabel it | |
| 467 | + * without reimplementing this markup; the default is unchanged. | |
| 468 | + * | |
| 469 | + * @param string $text | |
| 470 | + */ | |
| 471 | + echo esc_html(apply_filters('fluent_cart/cart/checkout_button_text', __('Go to Checkout', 'fluent-cart'))); | |
| 472 | + ?> | |
| 416 | 473 | </a> |
| 417 | 474 | |
| 418 | 475 | <?php |
| 419 | 476 | |