2025-12-21 04:56:50 +01:00
< ? php
/**
* Product meta boxes for tier and package pricing
*/
if ( ! defined ( 'ABSPATH' )) {
exit ;
}
Release version 1.1.13 - Critical class redeclaration fixes
Fixed critical class redeclaration errors affecting all plugin functionality
in version 1.1.12. All plugin component classes now properly guarded.
**CRITICAL FIXES:**
- Plugin completely non-functional in v1.1.12 (no settings, no frontend, no backend)
- Fatal errors for WC_TPP_Admin, WC_TPP_Product_Meta, WC_TPP_Frontend, WC_TPP_Cart, WC_TPP_Settings classes
- All classes now wrapped in class_exists() checks
**Files Modified:**
- includes/class-wc-tpp-admin.php
- includes/class-wc-tpp-product-meta.php
- includes/class-wc-tpp-frontend.php
- includes/class-wc-tpp-cart.php
- includes/class-wc-tpp-settings.php
**Technical Details:**
- Completes comprehensive redeclaration protection started in v1.1.9-1.1.12
- All 2 functions, 4 constants, and 6 classes now protected
- Plugin activates successfully and all features functional
- Settings page, product meta boxes, frontend display, cart integration all working
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-22 19:02:18 +01:00
if ( ! class_exists ( 'WC_TPP_Product_Meta' )) {
class WC_TPP_Product_Meta {
2025-12-21 04:56:50 +01:00
public function __construct () {
add_action ( 'woocommerce_product_options_pricing' , array ( $this , 'add_tier_pricing_fields' ));
add_action ( 'woocommerce_product_options_pricing' , array ( $this , 'add_package_pricing_fields' ));
add_action ( 'woocommerce_process_product_meta' , array ( $this , 'save_tier_package_fields' ));
}
public function add_tier_pricing_fields () {
global $post ;
?>
< div class = " options_group wc-tpp-tier-pricing " >
< p class = " form-field " >
< label >< ? php _e ( 'Tier Pricing' , 'wc-tier-package-prices' ); ?> </label>
< span class = " description " >< ? php _e ( 'Set quantity-based pricing tiers. Customers get discounted prices when buying in larger quantities.' , 'wc-tier-package-prices' ); ?> </span>
</ p >
< div class = " wc-tpp-tiers-container " >
< ? php
$tiers = get_post_meta ( $post -> ID , '_wc_tpp_tiers' , true );
if ( ! is_array ( $tiers )) {
$tiers = array ();
}
foreach ( $tiers as $index => $tier ) {
$this -> render_tier_row ( $index , $tier );
}
?>
</ div >
< p class = " form-field " >
< button type = " button " class = " button wc-tpp-add-tier " >< ? php _e ( 'Add Tier' , 'wc-tier-package-prices' ); ?> </button>
</ p >
</ div >
< ? php
}
public function add_package_pricing_fields () {
global $post ;
?>
< div class = " options_group wc-tpp-package-pricing " >
< p class = " form-field " >
< label >< ? php _e ( 'Package Pricing' , 'wc-tier-package-prices' ); ?> </label>
< span class = " description " >< ? php _e ( 'Set fixed-price packages with specific quantities. For example: 10 pieces for $50, 25 pieces for $100.' , 'wc-tier-package-prices' ); ?> </span>
</ p >
< div class = " wc-tpp-packages-container " >
< ? php
$packages = get_post_meta ( $post -> ID , '_wc_tpp_packages' , true );
if ( ! is_array ( $packages )) {
$packages = array ();
}
foreach ( $packages as $index => $package ) {
$this -> render_package_row ( $index , $package );
}
?>
</ div >
< p class = " form-field " >
< button type = " button " class = " button wc-tpp-add-package " >< ? php _e ( 'Add Package' , 'wc-tier-package-prices' ); ?> </button>
</ p >
2025-12-21 15:54:04 +01:00
< ? php
woocommerce_wp_checkbox ( array (
'id' => '_wc_tpp_restrict_to_packages' ,
'label' => __ ( 'Restrict to Package Quantities' , 'wc-tier-package-prices' ),
'description' => __ ( 'Only allow quantities defined in packages above' , 'wc-tier-package-prices' ),
'desc_tip' => true ,
));
?>
2025-12-21 04:56:50 +01:00
</ div >
< script type = " text/html " id = " wc-tpp-tier-row-template " >
2025-12-22 00:15:48 +01:00
< ? php $this -> render_tier_row ( '{{INDEX}}' , array ( 'min_qty' => '' , 'price' => '' , 'label' => '' )); ?>
2025-12-21 04:56:50 +01:00
</ script >
< script type = " text/html " id = " wc-tpp-package-row-template " >
< ? php $this -> render_package_row ( '{{INDEX}}' , array ( 'qty' => '' , 'price' => '' , 'label' => '' )); ?>
</ script >
< ? php
}
private function render_tier_row ( $index , $tier ) {
WC_TPP_Template_Loader :: get_instance () -> display ( 'admin/tier-row.twig' , array (
'index' => $index ,
'tier' => $tier
));
}
private function render_package_row ( $index , $package ) {
WC_TPP_Template_Loader :: get_instance () -> display ( 'admin/package-row.twig' , array (
'index' => $index ,
'package' => $package
));
}
public function save_tier_package_fields ( $post_id ) {
// Verify nonce for security
if ( ! isset ( $_POST [ 'woocommerce_meta_nonce' ]) || ! wp_verify_nonce ( $_POST [ 'woocommerce_meta_nonce' ], 'woocommerce_save_data' )) {
return ;
}
// Check user permissions
if ( ! current_user_can ( 'edit_post' , $post_id )) {
return ;
}
// Avoid auto-save
if ( defined ( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return ;
}
// Save tier pricing
if ( isset ( $_POST [ '_wc_tpp_tiers' ])) {
$tiers = array ();
foreach ( $_POST [ '_wc_tpp_tiers' ] as $tier ) {
if ( ! empty ( $tier [ 'min_qty' ]) && ! empty ( $tier [ 'price' ])) {
$tiers [] = array (
'min_qty' => absint ( $tier [ 'min_qty' ]),
2025-12-22 00:15:48 +01:00
'price' => wc_format_decimal ( $tier [ 'price' ]),
'label' => sanitize_text_field ( $tier [ 'label' ] ? ? '' )
2025-12-21 04:56:50 +01:00
);
}
}
// Sort by minimum quantity
usort ( $tiers , function ( $a , $b ) {
return $a [ 'min_qty' ] - $b [ 'min_qty' ];
});
update_post_meta ( $post_id , '_wc_tpp_tiers' , $tiers );
} else {
delete_post_meta ( $post_id , '_wc_tpp_tiers' );
}
// Save package pricing
if ( isset ( $_POST [ '_wc_tpp_packages' ])) {
$packages = array ();
foreach ( $_POST [ '_wc_tpp_packages' ] as $package ) {
if ( ! empty ( $package [ 'qty' ]) && ! empty ( $package [ 'price' ])) {
$packages [] = array (
'qty' => absint ( $package [ 'qty' ]),
'price' => wc_format_decimal ( $package [ 'price' ]),
'label' => sanitize_text_field ( $package [ 'label' ])
);
}
}
// Sort by quantity
usort ( $packages , function ( $a , $b ) {
return $a [ 'qty' ] - $b [ 'qty' ];
});
update_post_meta ( $post_id , '_wc_tpp_packages' , $packages );
} else {
delete_post_meta ( $post_id , '_wc_tpp_packages' );
}
2025-12-21 15:54:04 +01:00
// Save package quantity restriction setting
$restrict_to_packages = isset ( $_POST [ '_wc_tpp_restrict_to_packages' ]) ? 'yes' : 'no' ;
update_post_meta ( $post_id , '_wc_tpp_restrict_to_packages' , $restrict_to_packages );
2025-12-21 04:56:50 +01:00
}
}
2025-12-22 19:32:47 +01:00
new WC_TPP_Product_Meta ();
Release version 1.1.13 - Critical class redeclaration fixes
Fixed critical class redeclaration errors affecting all plugin functionality
in version 1.1.12. All plugin component classes now properly guarded.
**CRITICAL FIXES:**
- Plugin completely non-functional in v1.1.12 (no settings, no frontend, no backend)
- Fatal errors for WC_TPP_Admin, WC_TPP_Product_Meta, WC_TPP_Frontend, WC_TPP_Cart, WC_TPP_Settings classes
- All classes now wrapped in class_exists() checks
**Files Modified:**
- includes/class-wc-tpp-admin.php
- includes/class-wc-tpp-product-meta.php
- includes/class-wc-tpp-frontend.php
- includes/class-wc-tpp-cart.php
- includes/class-wc-tpp-settings.php
**Technical Details:**
- Completes comprehensive redeclaration protection started in v1.1.9-1.1.12
- All 2 functions, 4 constants, and 6 classes now protected
- Plugin activates successfully and all features functional
- Settings page, product meta boxes, frontend display, cart integration all working
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-22 19:02:18 +01:00
}