When working with WooCommerce stores that use custom fulfillment logic—like SFM (Ship From Manufacturer)—edge cases can break the standard add-to-cart flow. One common issue occurs when out-of-stock products are still purchasable via an alternate fulfillment method, but fail to properly add to the cart.
In this guide, we’ll walk through how this issue was diagnosed and resolved, including handling AJAX requests, modal interactions, and conditional cart behavior across multiple manufacturers.
Issue Background
A WooCommerce store using a custom SFM (Ship From Manufacturer) workflow encountered a critical issue:
- Products marked as out of stock but SFM-eligible displayed as “In Stock”
- Users could trigger the SFM confirmation modal
- However, after clicking “Add to Cart” inside the modal, nothing happened
- The product would only appear in the cart after a manual page refresh
Additionally, edge cases appeared when:
- Adding multiple SFM products from the same manufacturer
- Adding SFM products from different manufacturers
- Handling SFM-only SKUs (products that never had stock)
This created inconsistent cart behavior and blocked conversions.
Diagnosis
The issue was traced to a combination of frontend and backend logic:
1. AJAX request not completing properly
The modal triggered correctly, but the add-to-cart action:
- Did not consistently fire or complete
- Required a manual refresh to reflect changes
2. Manufacturer-based SFM state not handled correctly
The system tracks SFM activation per manufacturer, but:
- Adding a second product from the same manufacturer sometimes triggered an “out of stock” error
- The system didn’t properly recognize that SFM was already enabled
3. Inconsistent modal logic
There was no clear distinction between:
- First-time SFM activation (modal required)
- Subsequent product additions (modal should be skipped)
4. Custom mu-plugin involvement
The behavior was tied to a must-use plugin (mu-plugin) controlling SFM logic, meaning:
- Core WooCommerce behavior was overridden
- Debugging required reviewing custom logic rather than standard hooks
Resolution Steps
Step 1: Ensure AJAX add-to-cart completes and refreshes state
Update the modal confirmation handler to:
- Trigger a proper AJAX add-to-cart request
- Force a page refresh (or dynamically update cart state)
$('.sfm-confirm-button').on('click', function() {
$(this).prop('disabled', true).text('Processing...');
$.post(ajaxurl, {
action: 'woocommerce_add_to_cart',
product_id: productID,
quantity: qty
}).done(function() {
location.reload();
});
});
Step 2: Track SFM activation per manufacturer
Implement logic to store SFM state per manufacturer (session or cart-based):
$enabled_manufacturers = WC()->session->get('sfm_enabled', []);
if (!in_array($manufacturer_id, $enabled_manufacturers)) {
// Show modal
} else {
// Skip modal and add directly
}
Update the session after confirmation:
$enabled_manufacturers[] = $manufacturer_id;
WC()->session->set('sfm_enabled', $enabled_manufacturers);
Step 3: Adjust modal behavior logic
- First product from manufacturer → Show SFM modal
- Additional products from same manufacturer → Skip modal, add directly
- Products from a different manufacturer → Show modal again
Step 4: Fix out-of-stock validation conflicts
add_filter('woocommerce_is_purchasable', function($purchasable, $product) {
if (is_sfm_eligible($product)) {
return true;
}
return $purchasable;
}, 10, 2);
Step 5: Improve UX feedback during processing
- Disable the button after click
- Show “Processing…” state
- Optionally add visual indicators
Step 6: Minor UI improvements
- Add spacing between list items for readability
- Ensure modal messaging clearly explains SFM behavior
- Confirm cart updates visually after reload
Final Outcome
After implementing these fixes:
- SFM-eligible out-of-stock products can be added to cart reliably
- The add-to-cart flow works without manual refresh confusion
- Modal behavior is consistent and non-redundant
- Manufacturer-based logic works correctly across multiple products
- UX is improved with clear feedback during processing
If you’re dealing with complex WooCommerce behavior like custom fulfillment logic, AJAX cart issues, or plugin conflicts, our team can help diagnose and implement scalable solutions.