fix(tax): Tax rates now saving correctly + shadcn Select
## Fixed Critical Issues: ### 1. Tax Rates Not Appearing (FIXED ✅) **Root Cause:** get_tax_rates() was filtering by tax_class, but empty tax_class (standard) was not matching. **Solution:** Modified get_tax_rates() to treat empty string as standard class: ```php if ( $tax_class === 'standard' ) { // Match both empty string and 'standard' WHERE tax_rate_class = '' OR tax_rate_class = 'standard' } ``` ### 2. Select Dropdown Not Using Shadcn (FIXED ✅) **Problem:** Native select with manual styling was inconsistent. **Solution:** - Added selectedTaxClass state - Used controlled shadcn Select component - Initialize state when dialog opens/closes - Pass state value to API instead of form data ## Changes: - **Backend:** Fixed get_tax_rates() SQL query - **Frontend:** Converted to controlled Select with state - **UX:** Tax rates now appear immediately after creation ## Testing: - ✅ Add tax rate manually - ✅ Add suggested tax rate - ✅ Rates appear in list - ✅ Select dropdown uses shadcn styling
This commit is contained in:
@@ -171,14 +171,23 @@ class TaxController extends WP_REST_Controller {
|
||||
private function get_tax_rates( $tax_class ) {
|
||||
global $wpdb;
|
||||
|
||||
$rates = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
// For 'standard' class, match both empty string and 'standard'
|
||||
if ( $tax_class === 'standard' ) {
|
||||
$rates = $wpdb->get_results(
|
||||
"SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates
|
||||
WHERE tax_rate_class = %s
|
||||
ORDER BY tax_rate_order ASC",
|
||||
$tax_class
|
||||
)
|
||||
);
|
||||
WHERE tax_rate_class = '' OR tax_rate_class = 'standard'
|
||||
ORDER BY tax_rate_order ASC"
|
||||
);
|
||||
} else {
|
||||
$rates = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates
|
||||
WHERE tax_rate_class = %s
|
||||
ORDER BY tax_rate_order ASC",
|
||||
$tax_class
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$formatted_rates = array();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user