diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c25e55..70bcdc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,43 @@ All notable changes to WooCommerce Tier and Package Prices will be documented in The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.8] - 2025-12-30 + +### Fixed + +- **Currency Symbol Missing in Admin Headers and Placeholders**: Table headers in the admin pricing configuration now display "Price (CURRENCY)" instead of just "Price", making it immediately clear which currency is being used. Price input placeholders now show currency symbol (e.g., "e.g., 9.99 $" instead of "e.g., 9.99"), providing better UX for administrators configuring pricing in different currencies. + +- **Variation Pricing Data Not Deleted Properly (Critical)**: When administrators deleted all tier or package pricing entries from a variation (or simple/parent product) and saved, the empty pricing data was still stored in the database instead of being deleted. This caused variations to retain deleted pricing rules. The save logic now properly detects when the filtered pricing arrays are empty after removing invalid entries and deletes the post meta instead of saving empty arrays. + +### Technical Details + +**Currency Symbol Enhancement**: +- Updated all table headers to use `printf(__('Price (%s)', 'wc-tier-package-prices'), get_woocommerce_currency_symbol())` +- Modified `render_tier_row()` and `render_package_row()` methods to pass `currency_symbol` to Twig templates +- Updated `render_variation_tier_row()` and `render_variation_package_row()` with same currency symbol parameter +- Changed Twig template placeholders from `'e.g., 9.99'` to `('e.g., 9.99 ' ~ currency_symbol)` +- Affects all pricing contexts: simple products, variable product parents, and variations + +**Pricing Deletion Fix**: +- Modified `save_tier_package_fields()` method (simple/parent products) to check `if (!empty($tiers))` before saving +- Modified `save_variation_pricing_fields()` method (variations) with same empty check logic +- Changed logic from "save on isset, delete otherwise" to "filter entries, then save if not empty, delete if empty" +- Applies to both tier pricing and package pricing for all product types +- Root cause was filtering out empty entries but still calling `update_post_meta()` with an empty array + +**User Impact**: +- Administrators see currency symbol in all pricing configuration interfaces +- Clear indication of which currency prices should be entered in +- Deleting all pricing rules now properly removes them from the database +- No orphaned pricing data remains after deletion +- Works correctly for simple products, variable product parents, and variations + +### Changed Files + +- `includes/class-wc-tpp-product-meta.php` - Added currency symbol to all table headers; updated all render methods to pass currency symbol; fixed empty array deletion logic in both save methods +- `templates/admin/tier-row.twig` - Updated placeholder to include currency symbol +- `templates/admin/package-row.twig` - Updated placeholder to include currency symbol + ## [1.2.7] - 2025-12-30 ### Fixed diff --git a/composer.json b/composer.json index 54406c7..cb76771 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "magdev/wc-tier-package-prices", "description": "WooCommerce plugin for tier pricing and package prices with Twig templates", - "version": "1.2.7", + "version": "1.2.8", "type": "wordpress-plugin", "license": "GPL-2.0-or-later", "authors": [ diff --git a/includes/class-wc-tpp-product-meta.php b/includes/class-wc-tpp-product-meta.php index 2a5c776..6df0572 100644 --- a/includes/class-wc-tpp-product-meta.php +++ b/includes/class-wc-tpp-product-meta.php @@ -55,7 +55,7 @@ if (!class_exists('WC_TPP_Product_Meta')) { - + @@ -85,7 +85,7 @@ if (!class_exists('WC_TPP_Product_Meta')) { - + @@ -149,7 +149,7 @@ if (!class_exists('WC_TPP_Product_Meta')) { - + @@ -195,7 +195,7 @@ if (!class_exists('WC_TPP_Product_Meta')) { - + @@ -241,14 +241,16 @@ if (!class_exists('WC_TPP_Product_Meta')) { private function render_tier_row($index, $tier) { WC_TPP_Template_Loader::get_instance()->display('admin/tier-row.twig', array( 'index' => $index, - 'tier' => $tier + 'tier' => $tier, + 'currency_symbol' => get_woocommerce_currency_symbol() )); } private function render_package_row($index, $package) { WC_TPP_Template_Loader::get_instance()->display('admin/package-row.twig', array( 'index' => $index, - 'package' => $package + 'package' => $package, + 'currency_symbol' => get_woocommerce_currency_symbol() )); } @@ -285,7 +287,7 @@ if (!class_exists('WC_TPP_Product_Meta')) { - + @@ -308,7 +310,7 @@ if (!class_exists('WC_TPP_Product_Meta')) { - + @@ -363,7 +365,8 @@ if (!class_exists('WC_TPP_Product_Meta')) { WC_TPP_Template_Loader::get_instance()->display('admin/tier-row.twig', array( 'index' => $index, 'tier' => $tier, - 'field_prefix' => 'wc_tpp_tiers[' . $loop . ']' + 'field_prefix' => 'wc_tpp_tiers[' . $loop . ']', + 'currency_symbol' => get_woocommerce_currency_symbol() )); } @@ -378,7 +381,8 @@ if (!class_exists('WC_TPP_Product_Meta')) { WC_TPP_Template_Loader::get_instance()->display('admin/package-row.twig', array( 'index' => $index, 'package' => $package, - 'field_prefix' => 'wc_tpp_packages[' . $loop . ']' + 'field_prefix' => 'wc_tpp_packages[' . $loop . ']', + 'currency_symbol' => get_woocommerce_currency_symbol() )); } @@ -414,7 +418,12 @@ if (!class_exists('WC_TPP_Product_Meta')) { usort($tiers, function($a, $b) { return $a['min_qty'] - $b['min_qty']; }); - update_post_meta($post_id, '_wc_tpp_tiers', $tiers); + // Only save if we have valid tiers, otherwise delete + if (!empty($tiers)) { + update_post_meta($post_id, '_wc_tpp_tiers', $tiers); + } else { + delete_post_meta($post_id, '_wc_tpp_tiers'); + } } else { delete_post_meta($post_id, '_wc_tpp_tiers'); } @@ -435,7 +444,12 @@ if (!class_exists('WC_TPP_Product_Meta')) { usort($packages, function($a, $b) { return $a['qty'] - $b['qty']; }); - update_post_meta($post_id, '_wc_tpp_packages', $packages); + // Only save if we have valid packages, otherwise delete + if (!empty($packages)) { + update_post_meta($post_id, '_wc_tpp_packages', $packages); + } else { + delete_post_meta($post_id, '_wc_tpp_packages'); + } } else { delete_post_meta($post_id, '_wc_tpp_packages'); } @@ -473,7 +487,12 @@ if (!class_exists('WC_TPP_Product_Meta')) { usort($tiers, function($a, $b) { return $a['min_qty'] - $b['min_qty']; }); - update_post_meta($variation_id, '_wc_tpp_tiers', $tiers); + // Only save if we have valid tiers, otherwise delete + if (!empty($tiers)) { + update_post_meta($variation_id, '_wc_tpp_tiers', $tiers); + } else { + delete_post_meta($variation_id, '_wc_tpp_tiers'); + } } else { delete_post_meta($variation_id, '_wc_tpp_tiers'); } @@ -494,7 +513,12 @@ if (!class_exists('WC_TPP_Product_Meta')) { usort($packages, function($a, $b) { return $a['qty'] - $b['qty']; }); - update_post_meta($variation_id, '_wc_tpp_packages', $packages); + // Only save if we have valid packages, otherwise delete + if (!empty($packages)) { + update_post_meta($variation_id, '_wc_tpp_packages', $packages); + } else { + delete_post_meta($variation_id, '_wc_tpp_packages'); + } } else { delete_post_meta($variation_id, '_wc_tpp_packages'); } diff --git a/templates/admin/package-row.twig b/templates/admin/package-row.twig index 2461c38..123fe12 100644 --- a/templates/admin/package-row.twig +++ b/templates/admin/package-row.twig @@ -21,7 +21,7 @@ diff --git a/templates/admin/tier-row.twig b/templates/admin/tier-row.twig index cfccb51..1b8615f 100644 --- a/templates/admin/tier-row.twig +++ b/templates/admin/tier-row.twig @@ -21,7 +21,7 @@ diff --git a/wc-tier-and-package-prices.php b/wc-tier-and-package-prices.php index 1ef25be..2f401cf 100644 --- a/wc-tier-and-package-prices.php +++ b/wc-tier-and-package-prices.php @@ -4,7 +4,7 @@ * Plugin Name: WooCommerce Tier and Package Prices * Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-tier-package-prices * Description: Add tier pricing and package prices to WooCommerce products with configurable quantities at fixed prices - * Version: 1.2.7 + * Version: 1.2.8 * Author: Marco Graetsch * Author URI: https://src.bundespruefstelle.ch/magdev * Text Domain: wc-tier-package-prices @@ -23,7 +23,7 @@ if (!defined('ABSPATH')) { // Define plugin constants if (!defined('WC_TPP_VERSION')) { - define('WC_TPP_VERSION', '1.2.7'); + define('WC_TPP_VERSION', '1.2.8'); } if (!defined('WC_TPP_PLUGIN_DIR')) { define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));