You've already forked wc-tier-and-package-prices
## Bugfixes
1. **Price Header Not Translated**
- Fixed translation function placement in printf statements
- Changed from printf(__()) to printf(esc_html__())
- Headers now display in administrator's configured language
2. **Placeholder HTML Entity Encoding**
- Currency symbols were showing as HTML entities (e.g., €)
- Removed translation filter from concatenated placeholder strings
- Placeholders are example values that should not be translated
3. **Variation Pricing Still Not Deletable (Regression)**
- Despite v1.2.8 fix, edge cases remained due to conditional branching
- Refactored save logic to be more defensive
- Always initializes arrays, then unconditionally updates or deletes
- Guarantees proper cleanup regardless of POST data structure
## Technical Details
- Updated all 6 table headers: printf(esc_html__('Price (%s)', 'wc-tier-package-prices'), ...)
- Removed |__() filter from Twig placeholder concatenations
- Refactored save_variation_pricing_fields() with simplified logic:
* Initialize arrays at start
* Populate only if valid POST data exists
* Always perform update (if !empty) or delete (if empty)
- Added is_array() check for extra safety
## Changed Files
- includes/class-wc-tpp-product-meta.php
- templates/admin/tier-row.twig
- templates/admin/package-row.twig
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
129 lines
4.1 KiB
PHP
129 lines
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.9
|
|
* Author: Marco Graetsch
|
|
* Author URI: https://src.bundespruefstelle.ch/magdev
|
|
* Text Domain: wc-tier-package-prices
|
|
* Domain Path: /languages
|
|
* Requires at least: 6.0
|
|
* Requires PHP: 7.4
|
|
* WC requires at least: 8.0
|
|
* WC tested up to: 10.0
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit; // Exit if accessed directly
|
|
}
|
|
|
|
// Define plugin constants
|
|
if (!defined('WC_TPP_VERSION')) {
|
|
define('WC_TPP_VERSION', '1.2.9');
|
|
}
|
|
if (!defined('WC_TPP_PLUGIN_DIR')) {
|
|
define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
}
|
|
if (!defined('WC_TPP_PLUGIN_URL')) {
|
|
define('WC_TPP_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
}
|
|
if (!defined('WC_TPP_PLUGIN_BASENAME')) {
|
|
define('WC_TPP_PLUGIN_BASENAME', plugin_basename(__FILE__));
|
|
}
|
|
|
|
// Load Composer autoloader
|
|
require_once WC_TPP_PLUGIN_DIR . 'vendor/autoload.php';
|
|
|
|
/**
|
|
* Display WooCommerce missing notice
|
|
*/
|
|
if (!function_exists('wc_tpp_woocommerce_missing_notice')) {
|
|
function wc_tpp_woocommerce_missing_notice() {
|
|
?>
|
|
<div class="notice notice-error">
|
|
<p><?php _e('WooCommerce Tier and Package Prices requires WooCommerce to be installed and active.', 'wc-tier-package-prices'); ?></p>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if WooCommerce is active
|
|
*/
|
|
if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
|
|
add_action('admin_notices', 'wc_tpp_woocommerce_missing_notice');
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* Main plugin class
|
|
*/
|
|
if (!class_exists('WC_Tier_Package_Prices')) {
|
|
class WC_Tier_Package_Prices {
|
|
|
|
private static $instance = null;
|
|
|
|
public static function get_instance() {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
private function __construct() {
|
|
$this->init_hooks();
|
|
$this->includes();
|
|
}
|
|
|
|
private function init_hooks() {
|
|
add_action('plugins_loaded', array($this, 'load_textdomain'));
|
|
add_action('before_woocommerce_init', array($this, 'declare_hpos_compatibility'));
|
|
register_activation_hook(__FILE__, array($this, 'activate'));
|
|
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
|
|
}
|
|
|
|
private function includes() {
|
|
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-template-loader.php';
|
|
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-admin.php';
|
|
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-product-meta.php';
|
|
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-frontend.php';
|
|
require_once WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-cart.php';
|
|
}
|
|
|
|
public function declare_hpos_compatibility() {
|
|
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
|
|
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
|
|
}
|
|
}
|
|
|
|
public function load_textdomain() {
|
|
load_plugin_textdomain('wc-tier-package-prices', false, dirname(WC_TPP_PLUGIN_BASENAME) . '/languages');
|
|
}
|
|
|
|
public function activate() {
|
|
// Add default options
|
|
add_option('wc_tpp_enable_tier_pricing', 'yes');
|
|
add_option('wc_tpp_enable_package_pricing', 'yes');
|
|
add_option('wc_tpp_display_table', 'yes');
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
public function deactivate() {
|
|
flush_rewrite_rules();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Initialize the plugin
|
|
if (!function_exists('wc_tpp_init')) {
|
|
function wc_tpp_init() {
|
|
return WC_Tier_Package_Prices::get_instance();
|
|
}
|
|
}
|
|
|
|
add_action('plugins_loaded', 'wc_tpp_init', 11);
|