feat: cleanup and improvements for checkout fields

- Removed all debug logging (backend and frontend)
- Added filter hook 'woonoow_standard_checkout_field_keys' for extensibility
- Added form-row-wide class support to admin OrderForm
- Tax is automatically handled by WC's calculate_totals()
This commit is contained in:
Dwindi Ramadhana
2026-01-09 10:06:20 +07:00
parent 942fb48a0b
commit d3ec580ec8
3 changed files with 13 additions and 21 deletions

View File

@@ -1165,7 +1165,9 @@ export default function OrderForm({
.filter((f: any) => f.fieldset === 'shipping' && !f.hidden) .filter((f: any) => f.fieldset === 'shipping' && !f.hidden)
.sort((a: any, b: any) => (a.priority || 0) - (b.priority || 0)) .sort((a: any, b: any) => (a.priority || 0) - (b.priority || 0))
.map((field: any) => { .map((field: any) => {
const isWide = ['address_1', 'address_2'].includes(field.key.replace('shipping_', '')); // Check for full width: address fields or form-row-wide class from PHP
const hasFormRowWide = Array.isArray(field.class) && field.class.includes('form-row-wide');
const isWide = hasFormRowWide || ['address_1', 'address_2'].includes(field.key.replace('shipping_', ''));
const fieldKey = field.key.replace('shipping_', ''); const fieldKey = field.key.replace('shipping_', '');
return ( return (

View File

@@ -569,16 +569,6 @@ export default function Checkout() {
custom_fields: customFieldData, custom_fields: customFieldData,
}; };
// DEBUG: Log shipping data being sent
console.log('[WooNooW DEBUG] Order Shipping Data:', {
selectedShippingRate,
shippingCost,
shippingRatesCount: shippingRates.length,
foundRate: shippingRates.find(r => r.id === selectedShippingRate),
orderData_shipping_cost: orderData.shipping_cost,
orderData_shipping_title: orderData.shipping_title,
});
// Submit order // Submit order
const response = await apiClient.post('/checkout/submit', orderData); const response = await apiClient.post('/checkout/submit', orderData);
const data = (response as any).data || response; const data = (response as any).data || response;

View File

@@ -414,11 +414,6 @@ class CheckoutController {
} }
// Shipping (besteffort estimate) // Shipping (besteffort estimate)
// DEBUG: Log shipping data for troubleshooting
error_log('[WooNooW Shipping Debug] shipping_method: ' . ($payload['shipping_method'] ?? 'null'));
error_log('[WooNooW Shipping Debug] shipping_cost: ' . ($payload['shipping_cost'] ?? 'null'));
error_log('[WooNooW Shipping Debug] shipping_title: ' . ($payload['shipping_title'] ?? 'null'));
if (!empty($payload['shipping_method'])) { if (!empty($payload['shipping_method'])) {
$rate = $this->find_shipping_rate_for_order($order, $payload['shipping_method']); $rate = $this->find_shipping_rate_for_order($order, $payload['shipping_method']);
if ($rate instanceof WC_Shipping_Rate) { if ($rate instanceof WC_Shipping_Rate) {
@@ -431,7 +426,6 @@ class CheckoutController {
'taxes' => $rate->get_taxes(), 'taxes' => $rate->get_taxes(),
]); ]);
$order->add_item($item); $order->add_item($item);
error_log('[WooNooW Shipping Debug] Added shipping via WC rate lookup: ' . $rate->get_cost());
} elseif (!empty($payload['shipping_cost']) && $payload['shipping_cost'] > 0) { } elseif (!empty($payload['shipping_cost']) && $payload['shipping_cost'] > 0) {
// Fallback: use shipping_cost directly from frontend // Fallback: use shipping_cost directly from frontend
// This handles API-based shipping like Rajaongkir where WC zones don't apply // This handles API-based shipping like Rajaongkir where WC zones don't apply
@@ -449,9 +443,6 @@ class CheckoutController {
'total' => floatval($payload['shipping_cost']), 'total' => floatval($payload['shipping_cost']),
]); ]);
$order->add_item($item); $order->add_item($item);
error_log('[WooNooW Shipping Debug] Added shipping via frontend fallback: ' . $payload['shipping_cost']);
} else {
error_log('[WooNooW Shipping Debug] NO shipping added - rate lookup failed and no valid shipping_cost');
} }
} }
@@ -571,9 +562,10 @@ class CheckoutController {
/** /**
* Get list of standard WooCommerce field keys * Get list of standard WooCommerce field keys
* Plugins can extend this list via the 'woonoow_standard_checkout_field_keys' filter
*/ */
private function get_standard_field_keys(): array { private function get_standard_field_keys(): array {
return [ $keys = [
'billing_first_name', 'billing_first_name',
'billing_last_name', 'billing_last_name',
'billing_company', 'billing_company',
@@ -596,6 +588,14 @@ class CheckoutController {
'shipping_postcode', 'shipping_postcode',
'order_comments', 'order_comments',
]; ];
/**
* Filter the list of standard checkout field keys.
* Plugins can add their own field keys to be recognized as "standard" (not custom).
*
* @param array $keys List of standard field keys
*/
return apply_filters('woonoow_standard_checkout_field_keys', $keys);
} }
/** ----------------- Helpers ----------------- **/ /** ----------------- Helpers ----------------- **/