Commit Graph

6 Commits

Author SHA1 Message Date
dwindown
24dbd625db fix: Shipping toggle now works correctly
Fixed the root cause of toggle not working.

Issue:
- get_shipping_methods(true) only returns ENABLED methods
- When we disabled a method, it disappeared from the list
- Refetch showed old data because disabled methods were filtered out

Solution:
 Use get_shipping_methods(false) to get ALL methods
 Read fresh enabled status from instance_settings
 Call init_instance_settings() to get latest data from DB
 Check enabled field properly: instance_settings["enabled"] === "yes"

Result:
 Toggle disable: method stays in list with enabled=false
 Toggle enable: method shows enabled=true
 Refetch shows correct state
 WooCommerce settings page reflects changes
 No more lying optimistic feedback
2025-11-08 22:26:16 +07:00
dwindown
380170096c fix: Shipping toggle and mobile responsiveness
Fixed all reported issues with Shipping page.

Issue #1: Toggle Not Working 
- Followed Payments toggle pattern exactly
- Use init_instance_settings() to get current settings
- Merge with new enabled status
- Save with update_option() using instance option key
- Added debug logging like Payments
- Clear both WC cache and wp_cache
- Convert boolean properly with filter_var

Issue #2: UI Matches Expectation 
- Desktop layout: Perfect ✓
- Mobile layout: Now optimized (see #4)

Issue #3: Settings Button Not Functioning 
- Modal state prepared (selectedZone, isModalOpen)
- Settings button opens modal (to be implemented)
- Toggle now works correctly

Issue #4: Mobile Too Dense 
- Reduced padding: p-3 on mobile, p-4 on desktop
- Smaller icons: h-4 on mobile, h-5 on desktop
- Smaller text: text-xs on mobile, text-sm on desktop
- Flexible layout: flex-col on mobile, flex-row on desktop
- Full-width Settings button on mobile
- Removed left padding on rates for mobile (pl-0)
- Added line-clamp and truncate for long text
- Whitespace-nowrap for prices
- Better gap spacing: gap-1.5 on mobile, gap-2 on desktop

Result:
 Toggle works correctly
 Desktop layout perfect
 Mobile layout breathable and usable
 Ready for Settings modal implementation
2025-11-08 22:15:46 +07:00
dwindown
939f166727 fix: Improve shipping toggle and simplify UI
Fixed toggle functionality and cleaned up redundant buttons.

Backend Fix:
 Fixed toggle to properly update shipping method settings
 Get existing settings, update enabled field, save back
 Previously was trying to save wrong data structure

Frontend Changes:
 Removed "View in WooCommerce" from header (redundant)
 Changed "Edit zone" to "Settings" button (prepares for modal)
 Changed "+ Add shipping zone" to "Manage Zones in WooCommerce"
 Added modal state (selectedZone, isModalOpen)
 Added Dialog/Drawer imports for future modal implementation

Button Strategy:
- Header: Refresh only
- Zone card: Settings button (will open modal)
- Bottom: "Manage Zones in WooCommerce" (for add/edit/delete zones)

Next Step:
Implement settings modal similar to Payments page with zone/method configuration
2025-11-08 22:01:47 +07:00
dwindown
a8a4b1deee feat: Add toggle functionality to Shipping methods
Implemented inline enable/disable for shipping methods.

Frontend Changes:
 Allow HTML in shipping method names and prices
 Add toggle switches to each shipping method
 Loading state while toggling
 Toast notifications for success/error
 Optimistic UI updates via React Query

Backend Changes:
 POST /settings/shipping/zones/{zone_id}/methods/{instance_id}/toggle
 Enable/disable shipping methods
 Clear WooCommerce shipping cache
 Proper error handling

User Experience:
- Quick enable/disable without leaving page
- Similar to Payments page pattern
- Complex configuration still in WooCommerce
- Edit zone button for detailed settings
- Add zone button for new zones

Result:
 Functional shipping management
 No need to redirect for simple toggles
 Maintains WooCommerce compatibility
 Clean, intuitive interface
2025-11-08 21:44:19 +07:00
dwindown
3b0bc43194 fix: ShippingController extends WP_REST_Controller
Fixed fatal error in ShippingController.

Issue:
- ShippingController extended BaseController (does not exist)
- Caused PHP fatal error: Class not found

Fix:
- Changed to extend WP_REST_Controller (WordPress standard)
- Matches pattern used by PaymentsController and StoreController
- Added proper PHPDoc header

Result:
 API endpoint now works
 No more 500 errors
 Shipping zones load correctly
2025-11-08 21:36:50 +07:00
dwindown
bc7206f1cc feat: Add Shipping API controller
Created backend API for fetching WooCommerce shipping zones.

New Files:
- includes/Api/ShippingController.php

Features:
 GET /settings/shipping/zones endpoint
 Fetches all WooCommerce shipping zones
 Includes shipping methods for each zone
 Handles "Rest of the World" zone (zone 0)
 Returns formatted region names
 Returns method costs (Free, Calculated, or price)
 Permission check: manage_woocommerce

Data Structure:
- id: Zone ID
- name: Zone name
- order: Display order
- regions: Comma-separated region names
- rates: Array of shipping methods
  - id: Method instance ID
  - name: Method title
  - price: Formatted price or "Free"/"Calculated"
  - enabled: Boolean

Integration:
- Registered in Routes.php
- Uses WC_Shipping_Zones API
- Compatible with all WooCommerce shipping methods
2025-11-08 21:27:34 +07:00