Browse Source

Override WC block-cart "Estimated total" via wp.i18n — v1.5.12 -> v1.5.13

The gettext_woocommerce PHP filter added in 1.5.12 catches server-rendered
strings only. The WC block cart is React-rendered and reads its labels
from wp.i18n, hydrated from a separate wc-cart-checkout-base-js
translations bundle — so "Odhadovaný součet" still showed on the cart
page.

Fix: wp_add_inline_script on the wp-i18n handle with an "after" payload
that calls wp.i18n.setLocaleData({ 'Estimated total': […] }, 'woocommerce')
as soon as wp-i18n loads. Translation value is pulled from our own
textdomain via __('Total', …) so the string stays locale-aware.

Also remap "Cart totals" to the same wording for consistency.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Dalibor Votruba 2 tháng trước cách đây
mục cha
commit
3333cbf29a

+ 2 - 1
studiou-wc-free-photo-product/CLAUDE.md

@@ -2,7 +2,7 @@
 
 ## Project Overview
 
-WordPress/WooCommerce plugin called **studiou-wc-free-photo-product** (QDR - Studiou WC Free Photo Product) v1.5.12.
+WordPress/WooCommerce plugin called **studiou-wc-free-photo-product** (QDR - Studiou WC Free Photo Product) v1.5.13.
 Allows publishing special variable products where customers upload custom raw images to be printed for a price.
 
 ## Initial Requirements
@@ -52,6 +52,7 @@ Allows publishing special variable products where customers upload custom raw im
 1. `maybe_suppress_pvtfw()` detaches pvtfw's `print_table` and `available_options_btn` hooks on `wp` priority 5.
 1a. (1.5.12+) `maybe_suppress_pvtfw()` also detaches `woocommerce_template_single_price` at priority 10 so WC's price-range span (e.g. "10,00 Kč – 40,00 Kč") is hidden on FPP products — the per-variant table below replaces it.
 1b. (1.5.12+) `render_variant_price_table()` on `woocommerce_single_product_summary` priority 34 renders a read-only server-side table (`views/single-product-price-table.php`) above the dropzone: one row per variant with unit price (via `wc_price()`) and tiered quantity-discount badges. Pure overview — no radio/qty/add-to-cart.
+1c. (1.5.12+) `override_wc_strings()` on `gettext_woocommerce` reroutes selected WC core strings (currently "Estimated total") through our own textdomain so the translation lives in our .po. This catches PHP-rendered strings only. (1.5.13+) The block cart is React-rendered and reads strings from `wp.i18n` instead, so an inline script on the `wp-i18n` handle calls `wp.i18n.setLocaleData({ 'Estimated total': […], 'Cart totals': […] }, 'woocommerce')` after wp-i18n loads — overriding the bundled "Odhadovaný součet" in the live DOM.
 2. `render_upload_area()` on `woocommerce_single_product_summary` priority 35 passes variants + max uploads + existing batch files + hero preview URL to JS via `wp_localize_script('studiou-wcfpp-frontend', 'studiouFppCardData', ...)`.
 3. Browser renders:
    - **Dropzone** (multi-file `<input type="file" multiple>`) — accepts drag-drop + click-to-browse. Click-to-browse opens the native file picker via `$fileInput[0].click()` (NOT `$fileInput.trigger('click')`), because the `<input>` lives inside the dropzone element and a bubbling jQuery trigger re-entered the dropzone's own click handler, causing `Maximum call stack size exceeded` on mobile where the browser synthesizes an extra click when the picker closes (fixed in 1.5.11).

BIN
studiou-wc-free-photo-product/languages/studiou-wc-free-photo-product-cs_CZ.mo


+ 1 - 1
studiou-wc-free-photo-product/languages/studiou-wc-free-photo-product-cs_CZ.po

@@ -3,7 +3,7 @@
 # This file is distributed under the GPL v2 or later.
 msgid ""
 msgstr ""
-"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.5.12\n"
+"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.5.13\n"
 "Report-Msgid-Bugs-To: https://www.quadarax.com\n"
 "POT-Creation-Date: 2026-04-02 00:00+0000\n"
 "PO-Revision-Date: 2026-04-02 00:00+0000\n"

+ 1 - 1
studiou-wc-free-photo-product/languages/studiou-wc-free-photo-product.pot

@@ -2,7 +2,7 @@
 # This file is distributed under the GPL v2 or later.
 msgid ""
 msgstr ""
-"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.5.12\n"
+"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.5.13\n"
 "Report-Msgid-Bugs-To: https://www.quadarax.com\n"
 "POT-Creation-Date: 2026-04-02 00:00+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"

+ 4 - 0
studiou-wc-free-photo-product/readme.md

@@ -2,6 +2,10 @@
 
 WordPress (6.9.4+) / WooCommerce (10.6.2+) plugin that allows publishing special variable products with custom raw image upload for photo printing. Customers upload one or more photos on the product page and compose an order where each uploaded photo can be printed in a different variant at its own quantity. Uploaded files are stored in the WordPress media library under a configurable media category.
 
+## What's new in 1.5.13
+
+- **Cart "Estimated total" rename now actually reaches the block cart.** The 1.5.12 `gettext_woocommerce` PHP filter only catches PHP-rendered strings, but the WC block cart is React-rendered and pulls its labels from a separate `wc-cart-checkout-base-js-translations` bundle via `wp.i18n.__()`. Added an inline script on the `wp-i18n` handle that calls `wp.i18n.setLocaleData({ 'Estimated total': […] }, 'woocommerce')` as soon as wp-i18n loads, overriding the bundled Czech translation "Odhadovaný součet" with our own. Translation value still lives in our .po so it's locale-aware. Also remapped "Cart totals" for consistency.
+
 ## What's new in 1.5.12
 
 - **Read-only variant price table above the dropzone.** Customers see all variant prices plus the tiered quantity-discount schedule before they upload. Server-side table uses `wc_price()` so formatting follows the WC pipeline. Out-of-stock rows greyed out. Rendered on `woocommerce_single_product_summary` priority 34 (right before the upload area at priority 35).

+ 17 - 2
studiou-wc-free-photo-product/studiou-wc-free-photo-product.php

@@ -3,7 +3,7 @@
  * Plugin Name: QDR - Studiou WC Free Photo Product
  * Plugin URI: https://www.quadarax.com/plugins/studiou-wc-free-photo-product
  * Description: Allows publishing special WooCommerce products with variants and custom raw image upload for photo printing
- * Version: 1.5.12
+ * Version: 1.5.13
  * Requires at least: 6.9.4
  * Requires PHP: 8.2
  * Requires Plugins: woocommerce, product-variant-table-for-woocommerce
@@ -22,7 +22,7 @@ if (!defined('WPINC')) {
     die;
 }
 
-if (!defined('STUDIOU_WCFPP_VERSION')) define('STUDIOU_WCFPP_VERSION', '1.5.12');
+if (!defined('STUDIOU_WCFPP_VERSION')) define('STUDIOU_WCFPP_VERSION', '1.5.13');
 if (!defined('STUDIOU_WCFPP_PLUGIN_DIR')) define('STUDIOU_WCFPP_PLUGIN_DIR', plugin_dir_path(__FILE__));
 if (!defined('STUDIOU_WCFPP_PLUGIN_URL')) define('STUDIOU_WCFPP_PLUGIN_URL', plugin_dir_url(__FILE__));
 if (!defined('STUDIOU_WCFPP_PLUGIN_BASENAME')) define('STUDIOU_WCFPP_PLUGIN_BASENAME', plugin_basename(__FILE__));
@@ -246,6 +246,21 @@ class Studiou_WC_Free_Photo_Product {
     }
 
     public function register_frontend_assets() {
+        // WC block cart ("Estimated total" etc.) is React-rendered and pulls its strings
+        // from wp.i18n in the browser — the PHP gettext_woocommerce filter never fires for
+        // those strings. Patch the translation on the JS side: after wp-i18n loads, and
+        // before the cart block renders, replace the 'Estimated total' → 'woocommerce'
+        // domain entry with our own wording. Translation source of truth stays in our .po.
+        $override_js  = "( function() {";
+        $override_js .= " if ( ! window.wp || ! wp.i18n ) return;";
+        $override_js .= " var domain = 'woocommerce';";
+        $override_js .= " var txt = " . wp_json_encode(__('Total', 'studiou-wc-free-photo-product')) . ";";
+        $override_js .= " wp.i18n.setLocaleData( { 'Estimated total': [ txt ] }, domain );";
+        // Also remap other cart-page terminology variants so UI stays consistent.
+        $override_js .= " wp.i18n.setLocaleData( { 'Cart totals': [ txt ] }, domain );";
+        $override_js .= " } )();";
+        wp_add_inline_script('wp-i18n', $override_js, 'after');
+
         wp_register_style(
             'studiou-wcfpp-frontend',
             STUDIOU_WCFPP_PLUGIN_URL . 'assets/css/frontend.css',