← All changes
|
includes/widgets/Woo_Cart_Table/Woo_Cart_Table.php
+20
-3
51.1.85
→
51.1.87
View file →
| @@ -402,12 +402,15 @@ | ||
| 402 | 402 | private static function build_fragments(): array |
| 403 | 403 | { |
| 404 | 404 | $empty = WC()->cart->is_empty(); |
| 405 | 405 | |
| 406 | + // Capture notices before cart HTML. Previously render_cart_html() printed | |
| 407 | + // them first via woocommerce_output_all_notices(), so ajax fragments | |
| 408 | + // returned an empty notices string and the coupon widget stayed silent. | |
| 409 | + $notices = function_exists('wc_print_notices') ? wc_print_notices(true) : ''; | |
| 406 | 410 | $cart_html = $empty ? self::render_empty_cart_html() : self::render_cart_html(); |
| 407 | 411 | $totals_html = self::render_totals_html($empty); |
| 408 | 412 | $cross_html = self::render_cross_sells_html($empty); |
| 409 | - $notices = function_exists('wc_print_notices') ? wc_print_notices(true) : ''; | |
| 410 | 413 | |
| 411 | 414 | return [ |
| 412 | 415 | 'cart_html' => $cart_html, |
| 413 | 416 | 'totals_html' => $totals_html, |
| @@ -426,11 +429,25 @@ | ||
| 426 | 429 | */ |
| 427 | 430 | private static function render_cart_html(): string |
| 428 | 431 | { |
| 429 | 432 | ob_start(); |
| 430 | - woocommerce_output_all_notices(); | |
| 433 | + $had_totals = has_action('woocommerce_cart_collaterals', 'woocommerce_cart_totals'); | |
| 434 | + $had_cross = has_action('woocommerce_cart_collaterals', 'woocommerce_cross_sell_display'); | |
| 435 | + if ($had_totals) { | |
| 436 | + remove_action('woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10); | |
| 437 | + } | |
| 438 | + if ($had_cross) { | |
| 439 | + remove_action('woocommerce_cart_collaterals', 'woocommerce_cross_sell_display', 10); | |
| 440 | + } | |
| 431 | 441 | wc_get_template('cart/cart.php'); |
| 432 | - return (string) ob_get_clean(); | |
| 442 | + if ($had_totals) { | |
| 443 | + add_action('woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10); | |
| 444 | + } | |
| 445 | + if ($had_cross) { | |
| 446 | + add_action('woocommerce_cart_collaterals', 'woocommerce_cross_sell_display', 10); | |
| 447 | + } | |
| 448 | + $html = (string) ob_get_clean(); | |
| 449 | + return (string) preg_replace('#<div class="cart-collaterals">\s*</div>#', '', $html); | |
| 433 | 450 | } |
| 434 | 451 | |
| 435 | 452 | /** |
| 436 | 453 | * Render totals HTML. |