fix: licensing table creation, consistent meta keys, checkout virtual detection

1. License table auto-creation:
   - Added ensure_tables() check on plugins_loaded
   - Tables created automatically if missing

2. Consistent licensing meta keys:
   - ProductsController now uses _woonoow_licensing_enabled
   - Matches LicensingModule and LicenseManager

3. Checkout virtual-only detection:
   - Added needs_shipping to Cart interface
   - Checkout uses cart.needs_shipping from WooCommerce API
   - Fallback to item-level virtual/downloadable check

4. Login redirect for logged-in users added previously
This commit is contained in:
Dwindi Ramadhana
2026-01-07 22:15:51 +07:00
parent f334e018fa
commit 2cc20ff760
5 changed files with 32 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ export interface Cart {
tax: number;
shipping: number;
total: number;
needs_shipping?: boolean;
coupon?: {
code: string;
discount: number;

View File

@@ -41,11 +41,17 @@ export default function Checkout() {
const [discountTotal, setDiscountTotal] = useState(0);
const user = (window as any).woonoowCustomer?.user;
// Check if cart contains only virtual/downloadable products
// Check if cart needs shipping (virtual-only carts don't need shipping)
// Use cart.needs_shipping from WooCommerce API, fallback to item-level check
const isVirtualOnly = React.useMemo(() => {
// Prefer the needs_shipping flag from the cart API ( WooCommerce calculates this properly)
if (typeof cart.needs_shipping === 'boolean') {
return !cart.needs_shipping;
}
// Fallback: check individual items if needs_shipping not available
if (cart.items.length === 0) return false;
return cart.items.every(item => item.virtual || item.downloadable);
}, [cart.items]);
}, [cart.items, cart.needs_shipping]);
// Calculate totals
const subtotal = cart.items.reduce((sum, item) => sum + (item.price * item.quantity), 0);