WooCommerce/WordPress是否支持集成家政清洁、保姆类计时服务并自动算价?
Hey there! Great question—WooCommerce (built on WordPress) absolutely has the flexibility to handle service-based businesses like home cleaning or nanny services, including automatic pricing based on hours booked. Let me break down the most practical ways to set this up:
Hourly Pricing Setup for Service-Based Products in WooCommerce
1. Official WooCommerce Add-ons (Quick & Easy)
- Start by creating a Simple Product for your core service (e.g., "Home Cleaning").
- Use the WooCommerce Product Add-ons extension to add a custom input field for hours:
- Add a "Number" field where customers can type in how many hours they need. Set a price per hour (e.g., $25), and the plugin will automatically calculate the total (e.g., 3 hours × $25 = $75) when the customer adds the item to their cart.
- For predefined time blocks (like 1hr, 2hr, 4hr packages), use a "Dropdown" or "Radio Button" add-on instead—each option can be tied to a specific price (e.g., "2 Hours" = $50).
2. Variable Products for Tiered Service Rates
- If you offer different rates for different service types (e.g., $20/hr for regular cleaning, $30/hr for deep cleaning), a Variable Product is ideal:
- Create variations based on two attributes: "Service Type" and "Duration".
- For each variation, set the total price (or price per hour—WooCommerce will handle the math if you define it correctly). When customers select their service type and desired hours, the total price updates automatically.
3. Booking + Pricing Integration (For Full Scheduling)
- If you need to manage booking dates/times alongside hourly pricing, the Bookings for WooCommerce extension is purpose-built for this:
- Set a base hourly rate, define available time slots, and set minimum/maximum booking hours.
- Customers select their preferred date, time, and number of hours, and the system calculates the total price in real-time. It also syncs with calendars to prevent double-bookings—super useful for nanny or cleaning services where scheduling is critical.
4. Custom Code (For Full Control)
- If you’re comfortable with PHP, you can build custom functionality without plugins. Here’s a basic snippet to calculate hourly pricing based on a custom input field:
// Calculate total price based on hours selected add_action('woocommerce_before_calculate_totals', 'custom_hourly_price_calculation'); function custom_hourly_price_calculation($cart) { if (is_admin() && !defined('DOING_AJAX')) return; foreach ($cart->get_cart() as $item) { // Replace 123 with your service product's ID if ($item['product_id'] !== 123) continue; $hours = isset($item['custom_hours']) ? (int)$item['custom_hours'] : 1; $hourly_rate = 25; // Your base hourly rate $item['data']->set_price($hourly_rate * $hours); } } // Add a custom hours input field on the product page add_action('woocommerce_before_add_to_cart_button', 'add_hours_input_field'); function add_hours_input_field() { echo '<div class="hours-input"> <label for="custom_hours">Number of Hours:</label> <input type="number" id="custom_hours" name="custom_hours" min="1" value="1"> </div>'; } // Save the hours input to the cart item add_filter('woocommerce_add_cart_item_data', 'save_hours_to_cart', 10, 2); function save_hours_to_cart($cart_item_data, $product_id) { if (isset($_POST['custom_hours'])) { $cart_item_data['custom_hours'] = (int)$_POST['custom_hours']; $cart_item_data['unique_key'] = md5(microtime().rand()); // Ensure unique cart item } return $cart_item_data; }
- This code adds a number input for hours on your product page, saves that value to the cart, and calculates the total price based on your hourly rate.
Quick Tips
- Always test the flow end-to-end to make sure pricing updates correctly when customers adjust hours or select different options.
- Clearly display your hourly rate on the product page so customers understand how the total is calculated—transparency goes a long way!
内容的提问来源于stack exchange,提问作者MOJOJO
相关产品推荐
相关产品推荐

